Browse files

Rename MailForm::Resource to MailForm::Base and get rid of callbacks …

…(use new ActiveModel::Callbacks one).
  • Loading branch information...
1 parent 5db50ce commit 802e8750e957d6bcdb18e371adc524bd6d3f66b3 @josevalim josevalim committed Dec 29, 2009
Showing with 12 additions and 35 deletions.
  1. +5 −5 README.rdoc
  2. +1 −1 lib/mail_form.rb
  3. +2 −2 lib/mail_form/{resource.rb → base.rb}
  4. +0 −23 lib/mail_form/callbacks.rb
  5. +2 −2 lib/mail_form/shim.rb
  6. +2 −2 test/test_helper.rb
View
10 README.rdoc
@@ -15,7 +15,7 @@ on how to use MailForm in Rails 2.x, please check the v1.0 branch:
MailForm allows you to send an e-mail straight from a form. For instance,
if you want to make a contact form just the following lines are needed (including the e-mail):
- class ContactForm < MailForm::Resource
+ class ContactForm < MailForm::Base
subject "My Contact Form"
recipients "your.email@your.domain.com"
sender{|c| %{"#{c.name}" <#{c.email}>} }
@@ -36,9 +36,9 @@ Then you start a script/console and type:
Check your inbox and the e-mail will be there, with the sent fields (assuming that
you configured your mailer delivery method properly).
-=== MailForm::Resource
+=== MailForm::Base
-When you inherit from MailForm::Resource, it pulls down a set of stuff from ActiveModel,
+When you inherit from MailForm::Base, it pulls down a set of stuff from ActiveModel,
as ActiveModel::Validation, ActiveModel::Translation and ActiveModel::Naming.
This bring I18n, error messages, validations and attributes handling like in
@@ -107,7 +107,7 @@ Options:
Examples:
- class ContactForm < MailForm::Resource
+ class ContactForm < MailForm::Base
attributes :name, :validate => true
attributes :email, :validate => /[^@]+@[^\.]+\.[\w\.\-]+/
attributes :type, :validate => ["General", "Interface bug"]
@@ -171,7 +171,7 @@ Both the proc and the symbol must return a string or an array. By default is nil
MailForm also makes easy to append request information from client to the sent
mail. You just have to do:
- class ContactForm < MailForm::Resource
+ class ContactForm < MailForm::Base
append :remote_ip, :user_agent, :session
# ...
end
View
2 lib/mail_form.rb
@@ -1,7 +1,7 @@
class MailForm < ActionMailer::Base
+ autoload :Base, 'mail_form/base'
autoload :Callbacks, 'mail_form/callbacks'
autoload :Delivery, 'mail_form/delivery'
- autoload :Resource, 'mail_form/resource'
autoload :Shim, 'mail_form/shim'
self.template_root = File.expand_path('../views', File.dirname(__FILE__))
View
4 lib/mail_form/resource.rb → lib/mail_form/base.rb
@@ -1,8 +1,8 @@
-class MailForm::Resource
+class MailForm::Base
include MailForm::Shim
include MailForm::Delivery
def self.lookup_ancestors
- super - [MailForm::Resource]
+ super - [MailForm::Base]
end
end
View
23 lib/mail_form/callbacks.rb
@@ -1,23 +0,0 @@
-module MailForm::Callbacks
- def self.extended(base)
- base.class_eval do
- include ActiveSupport::Callbacks
- define_callbacks :create, :terminator => "result == false", :scope => [:kind, :name]
- end
- end
-
- def before_create(*args, &block)
- set_callback(:create, :before, *args, &block)
- end
-
- def around_create(*args, &block)
- set_callback(:create, :around, *args, &block)
- end
-
- def after_create(*args, &block)
- options = args.extract_options!
- options[:prepend] = true
- options[:if] = Array(options[:if]) << "!halted && value != false"
- set_callback(:create, :after, *(args << options), &block)
- end
-end
View
4 lib/mail_form/shim.rb
@@ -6,12 +6,12 @@ def self.included(base)
base.class_eval do
extend ActiveModel::Naming
extend ActiveModel::Translation
-
+ extend ActiveModel::Callbacks
include ActiveModel::Validations
include ActiveModel::Conversion
- extend MailForm::Callbacks
extend MailForm::Shim::ClassMethods
+ define_model_callbacks :create
end
end
View
4 test/test_helper.rb
@@ -15,7 +15,7 @@
$:.unshift File.dirname(__FILE__) + '/../lib'
require 'mail_form'
-class ContactForm < MailForm::Resource
+class ContactForm < MailForm::Base
recipients 'my.email@my.domain.com'
attribute :name, :validate => true
@@ -58,7 +58,7 @@ def set_recipient
end
end
-class NullRecipient < MailForm::Resource
+class NullRecipient < MailForm::Base
sender 'my.email@my.domain.com'
end

0 comments on commit 802e875

Please sign in to comment.