diff --git a/recipes/carrier_wave.rb b/recipes/carrier_wave.rb index 2a7988a..8c1e747 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,14 +38,23 @@ def cook } end CODE + end + def add_application_config @template.append_file '.env.sample', "\nAWS_ACCESS_KEY=''" - @template.append_file '.env', "\nAWS_ACCESS_KEY=''" @template.append_file '.env.sample', "\nAWS_SECRET_KEY=''" - @template.append_file '.env', "\nAWS_SECRET_KEY=''" @template.append_file '.env.sample', "\nAWS_S3_BUCKET=''" + @template.append_file '.env.sample', "\nFOG_DIRECTORY=''" + @template.append_file '.env', "\nAWS_ACCESS_KEY=''" + @template.append_file '.env', "\nAWS_SECRET_KEY=''" @template.append_file '.env', "\nAWS_S3_BUCKET=''" - end + @template.append_file '.env', "\nFOG_DIRECTORY=''" + 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