diff --git a/recipes/carrier_wave.rb b/recipes/carrier_wave.rb index 5a1fb77..6210fa5 100644 --- a/recipes/carrier_wave.rb +++ b/recipes/carrier_wave.rb @@ -8,10 +8,19 @@ class CarrierWave < Base def gems @template.gem 'carrierwave' + @template.gem 'asset_sync' @template.gem 'fog-aws' end def cook + add_initializer + add_application_config + add_production_env_config + end + + private + + def add_initializer @template.initializer 'carrierwave.rb', <<~CODE require 'carrierwave/storage/fog' CarrierWave.configure do |config| @@ -29,7 +38,9 @@ def cook } end CODE + end + def add_application_config @template.inside 'config' do @template.append_file 'application.yml.example', "\nAWS_ACCESS_KEY: ''" @template.append_file 'application.yml', "\nAWS_ACCESS_KEY: ''" @@ -40,5 +51,10 @@ def cook end end + def add_production_env_config + @template.gsub_file 'config/environments/production.rb', + '# config.action_controller.asset_host = \'http://assets.example.com\'', + 'config.action_controller.asset_host = "//#{ENV[\'FOG_DIRECTORY\']}.s3.amazonaws.com"' + end end end