mail_form 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ # Version 1.3
2
+
3
+ * Removed deprecated methods in version 1.2.
4
+ * Added persisted? header and a generator.
5
+
1
6
  # Version 1.2
2
7
 
3
8
  * No more class attributes, just define a headers method
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # coding: utf-8
2
+
1
3
  require 'rake'
2
4
  require 'rake/testtask'
3
5
  require 'rake/rdoctask'
@@ -0,0 +1,17 @@
1
+ module Rails
2
+ module Generators
3
+ class MailFormGenerator < Rails::Generators::NamedBase
4
+ def self.source_root
5
+ @_mail_form_source_root ||= File.expand_path("../templates", __FILE__)
6
+ end
7
+
8
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
9
+
10
+ check_class_collision
11
+
12
+ def create_model_file
13
+ template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ class <%= class_name %> < MailForm::Base
2
+ <% attributes.each do |attribute| -%>
3
+ attribute :<%= attribute.name %>
4
+ <% end -%>
5
+
6
+ def headers
7
+ { :to => "PLEASE-CHANGE-ME@example.org" }
8
+ end
9
+ end
@@ -15,42 +15,16 @@ module MailForm
15
15
  class_attribute :mail_appendable
16
16
  self.mail_appendable = []
17
17
 
18
- before_create :not_spam?
19
- after_create :deliver!
20
-
21
- attr_accessor :request
22
- alias :deliver :create
23
-
24
- extend Deprecated
25
- end
26
-
27
- module Deprecated
28
- def subject(duck=nil, &block)
29
- ActiveSupport::Deprecation.warn "subject is deprecated. Please define a headers method " <<
30
- "in your instance which returns a hash with :subject as key instead.", caller
31
- end
32
-
33
- def sender(duck=nil, &block)
34
- ActiveSupport::Deprecation.warn "from/sender is deprecated. Please define a headers method " <<
35
- "in your instance which returns a hash with :from as key instead.", caller
18
+ if respond_to?(:before_deliver) && respond_to?(:after_deliver)
19
+ before_deliver :not_spam?
20
+ after_deliver :deliver!
21
+ else # For ActiveRecord compatibility
22
+ before_create :not_spam?
23
+ after_create :deliver!
24
+ alias :deliver :save
36
25
  end
37
- alias :from :sender
38
26
 
39
- def recipients(duck=nil, &block)
40
- ActiveSupport::Deprecation.warn "to/recipients is deprecated. Please define a headers method " <<
41
- "in your instance which returns a hash with :to as key instead.", caller
42
- end
43
- alias :to :recipients
44
-
45
- def headers(hash)
46
- ActiveSupport::Deprecation.warn "headers is deprecated. Please define a headers method " <<
47
- "in your instance which returns the desired headers instead.", caller
48
- end
49
-
50
- def template(new_template)
51
- ActiveSupport::Deprecation.warn "template is deprecated. Please define a headers method " <<
52
- "in your instance which returns a hash with :template_name as key instead.", caller
53
- end
27
+ attr_accessor :request
54
28
  end
55
29
 
56
30
  module ClassMethods
@@ -169,7 +143,7 @@ module MailForm
169
143
  !spam?
170
144
  end
171
145
 
172
- # Deliver the resource without checking any condition.
146
+ # Deliver the resource without running any validation.
173
147
  def deliver!
174
148
  MailForm::Notifier.contact(self).deliver
175
149
  end
@@ -12,7 +12,7 @@ module MailForm
12
12
  include ActiveModel::Conversion
13
13
 
14
14
  extend MailForm::Shim::ClassMethods
15
- define_model_callbacks :create
15
+ define_model_callbacks :deliver
16
16
  end
17
17
  end
18
18
 
@@ -43,19 +43,23 @@ module MailForm
43
43
  true
44
44
  end
45
45
 
46
+ def persisted?
47
+ false
48
+ end
49
+
46
50
  # Always return nil so when using form_for, the default method will be post.
47
51
  def id
48
52
  nil
49
53
  end
50
54
 
51
55
  # Create just check validity, and if so, trigger callbacks.
52
- def create
56
+ def deliver
53
57
  if valid?
54
- _run_create_callbacks { true }
58
+ _run_deliver_callbacks { true }
55
59
  else
56
60
  false
57
61
  end
58
62
  end
59
- alias :save :create
63
+ alias :save :deliver
60
64
  end
61
65
  end
@@ -1,3 +1,3 @@
1
1
  module MailForm
2
- VERSION = "1.2.1".freeze
2
+ VERSION = "1.3.0".freeze
3
3
  end
@@ -1,3 +1,5 @@
1
+ # coding: utf-8
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class MailFormNotifierTest < ActiveSupport::TestCase
@@ -1,3 +1,5 @@
1
+ # coding: utf-8
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class MailFormBaseTest < ActiveSupport::TestCase
@@ -26,7 +26,7 @@ class ContactForm < MailForm::Base
26
26
 
27
27
  attributes :created_at, :message, :validate => :callback
28
28
 
29
- before_create :set_created_at
29
+ before_deliver :set_created_at
30
30
 
31
31
  def headers
32
32
  { :to => 'my.email@my.domain.com' }
@@ -55,14 +55,14 @@ end
55
55
 
56
56
  class FileForm < ContactForm
57
57
  attribute :file, :attachment => true, :validate => true
58
- recipients :set_recipient
59
58
 
60
- def set_recipient
61
- if file
59
+ def headers
60
+ to = if file
62
61
  "contact_file@my.domain.com"
63
62
  else
64
63
  "contact@my.domain.com"
65
64
  end
65
+ { :to => to }
66
66
  end
67
67
  end
68
68
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 2
8
- - 1
9
- version: 1.2.1
7
+ - 3
8
+ - 0
9
+ version: 1.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Jos\xC3\xA9 Valim"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-03 00:00:00 +02:00
18
+ date: 2010-05-26 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -32,6 +32,8 @@ files:
32
32
  - MIT-LICENSE
33
33
  - README.rdoc
34
34
  - Rakefile
35
+ - lib/generators/rails/mail_form_generator.rb
36
+ - lib/generators/rails/templates/model.rb
35
37
  - lib/mail_form.rb
36
38
  - lib/mail_form/base.rb
37
39
  - lib/mail_form/delivery.rb