From 10fe892a1fa8ef76a2ca4074cbad84ee455bc550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20G=C3=B3mez?= Date: Fri, 19 Oct 2018 12:15:17 +0200 Subject: [PATCH] Add asset_sync gem (#67) * Add asset_sync gem * Update to add dotenv support * Add FOG_DIRECTORY ENV --- recipes/carrier_wave.rb | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) 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