class JsonVoorhees::AppEnvironmentGenerator

Public Instance Methods

sprint() click to toggle source
# File lib/generators/json_voorhees/app_environment/app_environment_generator.rb, line 5
def sprint
     createSettings
     createDev
     createTest
     createPro
     addToApplication
end

Private Instance Methods

addToApplication() click to toggle source
# File lib/generators/json_voorhees/app_environment/app_environment_generator.rb, line 35
                       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],
          :expose => ['Logged-In-Status','Auth-Token','Main-Api-Header']      
      end
    end

        RUBY
        end
                       end
createDev() click to toggle source
# File lib/generators/json_voorhees/app_environment/app_environment_generator.rb, line 55
               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
createEnvSettings() click to toggle source
# File lib/generators/json_voorhees/app_environment/app_environment_generator.rb, line 23
       def createEnvSettings
                        prepend_to_file 'config/settings/development.yml' do
"main_api_key: \"123456789\"\n"
                        end
                        prepend_to_file 'config/settings/test.yml' do
"main_api_key: \"123456789\"\n"
                        end
                        prepend_to_file 'config/settings/production.yml' do
"main_api_key: \"123456789\"\n"
                        end
       end
createPro() click to toggle source
# File lib/generators/json_voorhees/app_environment/app_environment_generator.rb, line 106
               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
createSettings() click to toggle source
# File lib/generators/json_voorhees/app_environment/app_environment_generator.rb, line 15
               def createSettings
                       run "rails g rails_config:install"
                                prepend_to_file 'config/settings.yml' do
"token_header: \"Auth-Token\"\nmain_api_header: \"Main-Api-Header\"\n"
                                end
                                createEnvSettings
               end
createTest() click to toggle source
# File lib/generators/json_voorhees/app_environment/app_environment_generator.rb, line 80
               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