module AWS::Rails
def self.add_action_mailer_delivery_method name = :amazon_ses, options = {}
-
(nil)
-
Parameters:
-
options
(Hash
) -- A hash of options that are passes to -
name
(Symbol
) -- (:amazon_ses) The name of the delivery -
options
(Hash
) --
def self.add_action_mailer_delivery_method name = :amazon_ses, options = {} if ::Rails.version.to_f >= 3 ActiveSupport.on_load(:action_mailer) do self.add_delivery_method(name, AWS::SimpleEmailService, options) end else amb = ::ActionMailer::Base amb.send(:define_method, "perform_delivery_#{name}") do |mail| AWS::SimpleEmailService.new(options).send_raw_email(mail) end end nil end
def self.load_yaml_config
simple_db_consistent_reads: true
<<: *development
production:
simple_db_consistent_reads: false
secret_access_key: <%= read_secret_from_a_secure_location %>
access_key_id: YOUR_ACCESS_KEY_ID
development:
The yaml file will also be ERB parsed so you can use ruby inside of it:
simple_db_consistent_reads: true
<<: *development
production:
simple_db_consistent_reads: false
secret_access_key: YOUR_SECRET_ACCESS_KEY
access_key_id: YOUR_ACCESS_KEY_ID
development:
YAML references:
You should also consider DRYing up your configuration file using
simple_db_consistent_reads: true
secret_access_key: YOUR_SECRET_ACCESS_KEY
access_key_id: YOUR_ACCESS_KEY_ID
production:
simple_db_consistent_reads: false
secret_access_key: YOUR_SECRET_ACCESS_KEY
access_key_id: YOUR_ACCESS_KEY_ID
development:
should be one section for Rails environment:
standard +database.yml+ file in a Rails application. This means there
If you have a yaml configuration file it should be formatted like the
(e.g. RAILS_ROOT/config/intializers/aws.rb).
use ruby to configure AWS inside a configuration initialization script
This configuration file is optional. You can omit this file and instead
Loads AWS configuration options from +RAILS_ROOT/config/aws.yml+.
def self.load_yaml_config path = Pathname.new("#{rails_root}/config/aws.yml") if File.exists?(path) cfg = YAML::load(ERB.new(File.read(path)).result) unless cfg[rails_env] raise "config/aws.yml is missing a section for `#{rails_env}`" end AWS.config(cfg[rails_env]) end end
def self.log_to_rails_logger
-
(nil)
-
def self.log_to_rails_logger AWS.config(:logger => rails_logger) nil end
def self.rails_env
def self.rails_env ::Rails.respond_to?(:env) ? ::Rails.env : RAILS_ENV end
def self.rails_logger
def self.rails_logger ::Rails.respond_to?(:logger) ? ::Rails.logger : ::RAILS_DEFAULT_LOGGER end
def self.rails_root
def self.rails_root ::Rails.respond_to?(:root) ? ::Rails.root.to_s : RAILS_ROOT end
def self.setup
-
(nil)
-
def self.setup load_yaml_config add_action_mailer_delivery_method log_to_rails_logger nil end