has_emails 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,9 @@
1
1
  == master
2
2
 
3
+ == 0.1.3 / 2008-09-07
4
+
5
+ * Add compatibility with state_machine 0.3.0
6
+
3
7
  == 0.1.2 / 2008-06-29
4
8
 
5
9
  * Add compatibility with has_messages 0.1.2
data/README.rdoc CHANGED
@@ -91,6 +91,6 @@ To run against a specific version of Rails:
91
91
  == Dependencies
92
92
 
93
93
  * Rails 2.1 or later
94
- * plugins_plus[http://github.com/pluginaweek/plugins_plus]
95
94
  * has_messages[http://github.com/pluginaweek/has_messages]
96
95
  * state_machine[http://github.com/pluginaweek/state_machine]
96
+ * plugins_plus[http://github.com/pluginaweek/plugins_plugins] (optional if app files are copied to your project tree)
data/Rakefile CHANGED
@@ -5,15 +5,15 @@ require 'rake/contrib/sshpublisher'
5
5
 
6
6
  spec = Gem::Specification.new do |s|
7
7
  s.name = 'has_emails'
8
- s.version = '0.1.2'
8
+ s.version = '0.1.3'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.summary = 'Demonstrates a reference implementation for sending emails with logging and asynchronous support.'
11
11
 
12
- s.files = FileList['{app,db,lib,test}/**/*'].to_a - FileList['test/app_root/log/*'].to_a + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc)
12
+ s.files = FileList['{app,db,lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}']
13
13
  s.require_path = 'lib'
14
14
  s.has_rdoc = true
15
15
  s.test_files = Dir['test/**/*_test.rb']
16
- s.add_dependency 'has_messages', '>= 0.1.2'
16
+ s.add_dependency 'has_messages', '>= 0.1.3'
17
17
  s.add_dependency 'validates_as_email_address', '>= 0.0.2'
18
18
 
19
19
  s.author = 'Aaron Pfeifer'
data/app/models/email.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  # Represents an email which has been sent to one or more recipients. This is
2
- # essentially the same as the Message class, but overrides how the it is
2
+ # essentially the same as the Message class, but changes how the it is
3
3
  # delivered.
4
4
  class Email < Message
5
- after_deliver :deliver_email
5
+ state_machine :state do
6
+ after_transition :on => 'deliver', :do => :deliver_email
7
+ end
6
8
 
7
9
  private
8
- # Actually delivers the email to the recipients
10
+ # Actually delivers the email to the recipients using ActionMailer
9
11
  def deliver_email
10
12
  ActionMailer::Base.deliver_email(self)
11
13
  end
@@ -1,4 +1,17 @@
1
- # Represents a valid RFC822 email address
1
+ # Represents a valid RFC822 email address. See http://www.w3.org/Protocols/rfc822/
2
+ # for more information about the entire specification.
3
+ #
4
+ # Email addresses are directly associated with emails and, therefore, should be
5
+ # used for building and delivering new e-mails.
6
+ #
7
+ # == Associations
8
+ #
9
+ # Email addresses have the following associations defined as a result of using the
10
+ # +has_emails+ macro:
11
+ # * +emails+ - Emails that were composed and are visible to the owner. Emails may have been sent or unsent.
12
+ # * +received_emails+ - Emails that have been received from others and are visible. Emails may have been read or unread.
13
+ # * +unsent_emails+ - Emails that have not yet been delivered
14
+ # * +sent_emails+ - Emails that have already been delivered
2
15
  class EmailAddress < ActiveRecord::Base
3
16
  has_emails
4
17
 
@@ -14,7 +27,10 @@ class EmailAddress < ActiveRecord::Base
14
27
  find_or_create_by_name_and_spec(name, spec)
15
28
  end
16
29
 
17
- # Splits the given address into a name and spec
30
+ # Splits the given address into a name and spec. For example,
31
+ #
32
+ # EmailAddress.split_address("John Smith <john.smith@gmail.com") # => ["John Smith", "john.smith@gmail.com"]
33
+ # EmailAddress.split_address("john.smith@gmail.com") # => [nil, "john.smith@gmail.com"]
18
34
  def split_address(address)
19
35
  if match = /^(\S.*)\s+<(.*)>$/.match(address)
20
36
  name = match[1]
@@ -1,7 +1,21 @@
1
1
  module PluginAWeek #:nodoc:
2
2
  module HasEmails
3
3
  module Extensions #:nodoc:
4
+ # Adds support for queueing emails so that they can be procssed in the
5
+ # background. Emails are stored in the database using the Email ActiveRecord
6
+ # model.
4
7
  #
8
+ # == Queueing mail
9
+ #
10
+ # Once a mailer action and template are defined, you can queue your message
11
+ # for background processing like so:
12
+ #
13
+ # Notifier.queue_signup_notification(john_smith) # Queues the email
14
+ #
15
+ # If you were to deliver the mail immediately, the normal process would be
16
+ # used like so:
17
+ #
18
+ # Notifier.deliver_signup_notification(john_smith) # Delivers the email
5
19
  module ActionMailer
6
20
  def self.included(base) #:nodoc:
7
21
  base.class_eval do
@@ -9,7 +23,7 @@ module PluginAWeek #:nodoc:
9
23
  cattr_accessor :default_subject_prefix
10
24
 
11
25
  # Specify the prefix to use for the subject. This defaults to the
12
- # +default_subject_prefix+ specified for ApplicationMailer.
26
+ # +default_subject_prefix+ specified for ActionMailer::Base.
13
27
  adv_attr_accessor :subject_prefix
14
28
 
15
29
  include PluginAWeek::HasEmails::Extensions::ActionMailer::InstanceMethods
data/lib/has_emails.rb CHANGED
@@ -24,11 +24,9 @@ module PluginAWeek #:nodoc:
24
24
  # email = user.emails.build
25
25
  # email.subject = 'Hello'
26
26
  # email.body = 'How are you?'
27
- # email.to User.EmailAddress(456)
27
+ # email.to EmailAddress.find(456)
28
28
  # email.save!
29
29
  # email.deliver!
30
- #
31
- # Alternatively,
32
30
  def has_emails
33
31
  has_many :emails,
34
32
  :as => :sender,
@@ -47,12 +45,14 @@ module PluginAWeek #:nodoc:
47
45
  end
48
46
 
49
47
  module InstanceMethods
50
- # Composed emails that have not yet been sent
48
+ # Composed emails that have not yet been sent. These consists of all
49
+ # emails that are currently in the "unsent" state.
51
50
  def unsent_emails
52
51
  emails.with_state('unsent')
53
52
  end
54
53
 
55
- # Composed emails that have already been sent
54
+ # Composed emails that have already been sent. These consist of all emails
55
+ # that are currently in the "queued" or "sent states.
56
56
  def sent_emails
57
57
  emails.with_states(%w(queued sent))
58
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_emails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Pfeifer
@@ -9,20 +9,22 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-29 00:00:00 -04:00
12
+ date: 2008-09-07 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: has_messages
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
20
21
  - - ">="
21
22
  - !ruby/object:Gem::Version
22
- version: 0.1.2
23
+ version: 0.1.3
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: validates_as_email_address
27
+ type: :runtime
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
@@ -58,7 +60,6 @@ files:
58
60
  - test/app_root/db/migrate
59
61
  - test/app_root/db/migrate/001_migrate_has_messages_to_version_2.rb
60
62
  - test/app_root/db/migrate/002_migrate_has_emails_to_version_1.rb
61
- - test/app_root/log
62
63
  - test/functional
63
64
  - test/functional/has_emails_test.rb
64
65
  - test/test_helper.rb
@@ -94,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  requirements: []
95
96
 
96
97
  rubyforge_project: pluginaweek
97
- rubygems_version: 1.1.1
98
+ rubygems_version: 1.2.0
98
99
  signing_key:
99
100
  specification_version: 2
100
101
  summary: Demonstrates a reference implementation for sending emails with logging and asynchronous support.