diff --git a/lib/cybele/app_builder.rb b/lib/cybele/app_builder.rb index c80b4c9..2a50d13 100644 --- a/lib/cybele/app_builder.rb +++ b/lib/cybele/app_builder.rb @@ -17,6 +17,11 @@ def remove_readme_rdoc force: true end + def add_gems + # Add gems + append_file('Gemfile', template_content('cybele_Gemfile.erb')) + end + def add_editor_config copy_file 'editorconfig', '.editorconfig' end @@ -34,5 +39,22 @@ def use_postgres_config_template def create_database bundle_command 'exec rake db:create db:migrate' end + + def configure_recipient_interceptor + config = <<-RUBY + Mail.register_interceptor RecipientInterceptor.new(Settings.email.sandbox, subject_prefix: '[STAGING]') + RUBY + configure_environment 'staging', config + end + + def setup_staging_environment + run 'cp config/environments/production.rb config/environments/staging.rb' + end + + private + + def configure_environment(rails_env, config) + inject_into_file("config/environments/#{rails_env}.rb", "\n#{config}", before: "\nend") + end end end diff --git a/lib/cybele/generators/app_generator.rb b/lib/cybele/generators/app_generator.rb index 9ce6784..2f25144 100644 --- a/lib/cybele/generators/app_generator.rb +++ b/lib/cybele/generators/app_generator.rb @@ -57,6 +57,12 @@ def initialize(*args) @options.freeze end + def customize_gemfile + say 'Customize gem file', :green + build :add_gems + bundle_command 'install --binstubs=bin/stubs' + end + def setup_editor_config say 'Add .editor_config file', :green build :add_editor_config @@ -94,6 +100,16 @@ def setup_responders build :configure_responders end + def setup_staging_environment + say 'Setting up the staging environment' + build :setup_staging_environment + end + + def configure_recipient_interceptor + say 'Setup mail settings with recipient_interceptor in staging', :green + build :configure_recipient_interceptor + end + def goodbye say 'Congratulations! That\'s all...', :green end diff --git a/templates/cybele_Gemfile.erb b/templates/cybele_Gemfile.erb new file mode 100644 index 0000000..4034681 --- /dev/null +++ b/templates/cybele_Gemfile.erb @@ -0,0 +1,3 @@ + +# For never accidentally send emails to real people from staging environment. +gem 'recipient_interceptor', '~> 0.1.2' \ No newline at end of file