From 7409b734841c8bd691006634dd072212aa905cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim=20and=20Mikel=20Lindsaar?= Date: Sun, 24 Jan 2010 16:37:28 +0100 Subject: Some refactoring. --- actionmailer/lib/action_mailer/delivery_methods.rb | 92 ++++++++++------------ 1 file changed, 41 insertions(+), 51 deletions(-) (limited to 'actionmailer/lib/action_mailer/delivery_methods.rb') 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 -- cgit v1.2.3