module JsonVoorhees class AppEnvironmentGenerator < Rails::Generators::Base source_root File.expand_path('../templates', __FILE__) def sprint createSettings createDev createTest createPro addToApplication end private def createSettings run "rails g rails_config:install" prepend_to_file 'config/settings.yml' do "token_header: \"Auth_Token\"\napi_header: \"Api_Token\"\n" end end def addToApplication inject_into_file 'config/application.rb', after: "class Application < Rails::Application\n" do <<-'RUBY' #So url_for works in the mailer config.action_mailer.default_url_options = { host: 'localhost:3000' } #config.middleware.insert_before "ActionDispatch::Static", "Rack::Cors" do config.middleware.use Rack::Cors do allow do origins '*' resource '*', :headers => :any, :methods => [:get, :post, :put, :delete, :options] end end RUBY end end def createDev ::Settings.reload! gsub_file "config/environments/development.rb", "config.action_mailer.raise_delivery_errors = false\n", "#config.action_mailer.raise_delivery_errors = false\n" inject_into_file 'config/environments/development.rb', after: "configure do\n" do <<-'RUBY' config.action_mailer.perform_deliveries = false config.action_mailer.raise_delivery_errors = false config.action_mailer.default_options = {from: ENV['GMAIL_USERNAME']} config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: 'smtp.gmail.com', port: 587, domain: 'localhost:3000', user_name: ENV['GMAIL_USERNAME'], password: ENV['GMAIL_PASSWORD'], authentication: 'plain', enable_starttls_auto: true } ::Paperclip.options[:command_path] = "/usr/bin/" #Set Paperclip defaults here #Paperclip::Attachment.default_options[:storage] = :fog RUBY end end def createTest ::Settings.reload! gsub_file "config/environments/test.rb", "config.action_mailer.delivery_method = :test\n", "#config.action_mailer.delivery_method = :test\n" inject_into_file 'config/environments/test.rb', after: "configure do\n" do <<-'RUBY' #config.action_mailer.perform_deliveries = false config.action_mailer.raise_delivery_errors = true config.action_mailer.default_options = {from: 'testing123@example.com'} # Emails get sent here ::ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test config.action_mailer.smtp_settings = { address: 'smtp.gmail.com', port: 587, domain: 'localhost:3000', user_name: 'testing123', password: 'testing123', authentication: 'plain', enable_starttls_auto: true } ::Paperclip.options[:command_path] = "/usr/bin/" #Set Paperclip defaults here #Paperclip::Attachment.default_options[:storage] = :fog RUBY end end def createPro ::Settings.reload! inject_into_file 'config/environments/production.rb', after: "configure do\n" do <<-'RUBY' config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true config.action_mailer.default_options = {from: ENV['GMAIL_USERNAME']} config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: 'smtp.gmail.com', port: 587, domain: 'example.com', user_name: ENV['GMAIL_USERNAME'], password: ENV['GMAIL_PASSWORD'], authentication: 'plain', enable_starttls_auto: true } #May need to set Paperclip defaults here RUBY end end end end