Permalink
Browse files

Remove deprecated stuff and improve AR compatibility.

  • Loading branch information...
1 parent c8669a9 commit 5e815e1b8728e2e41648ce3b8e88e3a9fdfdb45f @josevalim josevalim committed May 26, 2010
Showing with 17 additions and 43 deletions.
  1. +9 −35 lib/mail_form/delivery.rb
  2. +4 −4 lib/mail_form/shim.rb
  3. +4 −4 test/test_helper.rb
View
@@ -15,42 +15,16 @@ module Delivery
class_attribute :mail_appendable
self.mail_appendable = []
- before_create :not_spam?
- after_create :deliver!
-
- attr_accessor :request
- alias :deliver :create
-
- extend Deprecated
- end
-
- module Deprecated
- def subject(duck=nil, &block)
- ActiveSupport::Deprecation.warn "subject is deprecated. Please define a headers method " <<
- "in your instance which returns a hash with :subject as key instead.", caller
- end
-
- def sender(duck=nil, &block)
- ActiveSupport::Deprecation.warn "from/sender is deprecated. Please define a headers method " <<
- "in your instance which returns a hash with :from as key instead.", caller
+ if respond_to?(:before_deliver) && respond_to?(:after_deliver)
+ before_deliver :not_spam?
+ after_deliver :deliver!
+ else # For ActiveRecord compatibility
+ before_create :not_spam?
+ after_create :deliver!
+ alias :deliver :save
end
- alias :from :sender
- def recipients(duck=nil, &block)
- ActiveSupport::Deprecation.warn "to/recipients is deprecated. Please define a headers method " <<
- "in your instance which returns a hash with :to as key instead.", caller
- end
- alias :to :recipients
-
- def headers(hash)
- ActiveSupport::Deprecation.warn "headers is deprecated. Please define a headers method " <<
- "in your instance which returns the desired headers instead.", caller
- end
-
- def template(new_template)
- ActiveSupport::Deprecation.warn "template is deprecated. Please define a headers method " <<
- "in your instance which returns a hash with :template_name as key instead.", caller
- end
+ attr_accessor :request
end
module ClassMethods
@@ -169,7 +143,7 @@ def not_spam?
!spam?
end
- # Deliver the resource without checking any condition.
+ # Deliver the resource without running any validation.
def deliver!
MailForm::Notifier.contact(self).deliver
end
View
@@ -12,7 +12,7 @@ def self.included(base)
include ActiveModel::Conversion
extend MailForm::Shim::ClassMethods
- define_model_callbacks :create
+ define_model_callbacks :deliver
end
end
@@ -53,13 +53,13 @@ def id
end
# Create just check validity, and if so, trigger callbacks.
- def create
+ def deliver
if valid?
- _run_create_callbacks { true }
+ _run_deliver_callbacks { true }
else
false
end
end
- alias :save :create
+ alias :save :deliver
end
end
View
@@ -26,7 +26,7 @@ class ContactForm < MailForm::Base
attributes :created_at, :message, :validate => :callback
- before_create :set_created_at
+ before_deliver :set_created_at
def headers
{ :to => 'my.email@my.domain.com' }
@@ -55,14 +55,14 @@ def headers
class FileForm < ContactForm
attribute :file, :attachment => true, :validate => true
- recipients :set_recipient
- def set_recipient
- if file
+ def headers
+ to = if file
"contact_file@my.domain.com"
else
"contact@my.domain.com"
end
+ { :to => to }
end
end

0 comments on commit 5e815e1

Please sign in to comment.