aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/delivery_methods.rb
diff options
context:
space:
mode:
authorJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-24 16:37:28 +0100
committerJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-24 16:37:28 +0100
commit7409b734841c8bd691006634dd072212aa905cf4 (patch)
tree2b2cc8b8836789d1e3801373a4982b80a682b54d /actionmailer/lib/action_mailer/delivery_methods.rb
parent73a9000402b5766e660dbf3489f5289c21c3f472 (diff)
downloadrails-7409b734841c8bd691006634dd072212aa905cf4.tar.gz
rails-7409b734841c8bd691006634dd072212aa905cf4.tar.bz2
rails-7409b734841c8bd691006634dd072212aa905cf4.zip
Some refactoring.
Diffstat (limited to 'actionmailer/lib/action_mailer/delivery_methods.rb')
-rw-r--r--actionmailer/lib/action_mailer/delivery_methods.rb92
1 files changed, 41 insertions, 51 deletions
diff --git a/actionmailer/lib/action_mailer/delivery_methods.rb b/actionmailer/lib/action_mailer/delivery_methods.rb
index 5883e446f2..16b84d4118 100644
--- a/actionmailer/lib/action_mailer/delivery_methods.rb
+++ b/actionmailer/lib/action_mailer/delivery_methods.rb
@@ -1,73 +1,63 @@
module ActionMailer
# This modules makes a DSL for adding delivery methods to ActionMailer
module DeliveryMethods
- extend ActiveSupport::Concern
-
- included do
- add_delivery_method :smtp, Mail::SMTP,
- :address => "localhost",
- :port => 25,
- :domain => 'localhost.localdomain',
- :user_name => nil,
- :password => nil,
- :authentication => nil,
- :enable_starttls_auto => true
-
- add_delivery_method :file, Mail::FileDelivery,
- :location => defined?(Rails.root) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails"
+ # TODO Make me class inheritable
+ def delivery_settings
+ @@delivery_settings ||= Hash.new { |h,k| h[k] = {} }
+ end
- add_delivery_method :sendmail, Mail::Sendmail,
- :location => '/usr/sbin/sendmail',
- :arguments => '-i -t'
+ def delivery_methods
+ @@delivery_methods ||= {}
+ end
- add_delivery_method :test, Mail::TestMailer
+ def delivery_method=(method)
+ raise ArgumentError, "Unknown delivery method #{method.inspect}" unless delivery_methods[method]
+ @delivery_method = method
+ end
- superclass_delegating_reader :delivery_method
- self.delivery_method = :smtp
+ def add_delivery_method(symbol, klass, default_options={})
+ self.delivery_methods[symbol] = klass
+ self.delivery_settings[symbol] = default_options
end
- module ClassMethods
- # TODO Make me class inheritable
- def delivery_settings
- @@delivery_settings ||= Hash.new { |h,k| h[k] = {} }
- end
+ def wrap_delivery_behavior(mail, method=nil)
+ method ||= delivery_method
- def delivery_methods
- @@delivery_methods ||= {}
- end
+ mail.register_for_delivery_notification(self)
- def delivery_method=(method)
- raise ArgumentError, "Unknown delivery method #{method.inspect}" unless delivery_methods[method]
- @delivery_method = method
+ if method.is_a?(Symbol)
+ mail.delivery_method(delivery_methods[method],
+ delivery_settings[method])
+ else
+ mail.delivery_method(method)
end
- def add_delivery_method(symbol, klass, default_options={})
- self.delivery_methods[symbol] = klass
- self.delivery_settings[symbol] = default_options
- end
+ mail.perform_deliveries = perform_deliveries
+ mail.raise_delivery_errors = raise_delivery_errors
+ end
- def respond_to?(method_symbol, include_private = false) #:nodoc:
- matches_settings_method?(method_symbol) || super
- end
- protected
+ def respond_to?(method_symbol, include_private = false) #:nodoc:
+ matches_settings_method?(method_symbol) || super
+ end
- # TODO Get rid of this method missing magic
- def method_missing(method_symbol, *parameters) #:nodoc:
- if match = matches_settings_method?(method_symbol)
- if match[2]
- delivery_settings[match[1].to_sym] = parameters[0]
- else
- delivery_settings[match[1].to_sym]
- end
+ protected
+
+ # TODO Get rid of this method missing magic
+ def method_missing(method_symbol, *parameters) #:nodoc:
+ if match = matches_settings_method?(method_symbol)
+ if match[2]
+ delivery_settings[match[1].to_sym] = parameters[0]
else
- super
+ delivery_settings[match[1].to_sym]
end
+ else
+ super
end
+ end
- def matches_settings_method?(method_name) #:nodoc:
- /(#{delivery_methods.keys.join('|')})_settings(=)?$/.match(method_name.to_s)
- end
+ def matches_settings_method?(method_name) #:nodoc:
+ /(#{delivery_methods.keys.join('|')})_settings(=)?$/.match(method_name.to_s)
end
end
end \ No newline at end of file