mail-control 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +12 -12
- data/lib/generators/{mail-control.rb → mail_control.rb} +1 -1
- data/lib/generators/{mail-control/activity → mail_control/logged_email}/activity_generator.rb +2 -2
- data/lib/generators/{mail-control/activity → mail_control/logged_email}/templates/logged_email.rb +0 -0
- data/lib/generators/{mail-control → mail_control}/migration/migration_generator.rb +2 -2
- data/lib/generators/{mail-control → mail_control}/migration/templates/migration.rb +0 -0
- data/lib/mail-control/actor.rb +5 -5
- data/lib/mail-control/logged_email.rb +8 -8
- data/lib/mail-control/version.rb +1 -1
- data/mail-control.gemspec +1 -0
- data/test/test_helper.rb +4 -4
- data/test/unit/activity_test.rb +11 -11
- data/test/unit/actor_test.rb +3 -3
- data/test/unit/definition_test.rb +2 -2
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28eec123b42a400284f71afc92e989d4f2877ea3
|
4
|
+
data.tar.gz: 6d766275023a1500be441f65cc9d2f54d5bb9265
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a6491f83866a569a8fc84686ce88fd5eafdacab1f530755a0e3283f7bedb65b9cdc2cd69b6ad14661f85b407467a4964e29e1b08dd4ce37d2c5593a90659f74
|
7
|
+
data.tar.gz: a57e599e6528aa33a559c90f9505b8ce306d2894be50f2e380b0ae6bc1795dc3c43d19b1a294ff0c1490fc4873b52de09197ba751f6b7b5823282357c41b8242
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -16,21 +16,21 @@ This gem is inspired by Streama by Christopher Pappas.
|
|
16
16
|
### Create migration for logged_emails and migrate the database (in your Rails project):
|
17
17
|
|
18
18
|
```ruby
|
19
|
-
rails g
|
19
|
+
rails g mail_control:migration
|
20
20
|
rake db:migrate
|
21
21
|
```
|
22
22
|
|
23
23
|
### Define Queued Task
|
24
24
|
|
25
|
-
Create an LoggedEmail model and define the logged_emails and the fields you would like to cache within the
|
25
|
+
Create an LoggedEmail model and define the logged_emails and the fields you would like to cache within the mailing.
|
26
26
|
|
27
|
-
An
|
27
|
+
An mailing consists of an actor, a verb, an act_object, and a target.
|
28
28
|
|
29
29
|
``` ruby
|
30
30
|
class LoggedEmail < ActiveRecord::Base
|
31
31
|
include MailControl::LoggedEmail
|
32
32
|
|
33
|
-
|
33
|
+
mailing :new_enquiry do
|
34
34
|
actor :User
|
35
35
|
act_object :Article
|
36
36
|
act_target :Volume
|
@@ -38,9 +38,9 @@ class LoggedEmail < ActiveRecord::Base
|
|
38
38
|
end
|
39
39
|
```
|
40
40
|
|
41
|
-
The
|
41
|
+
The mailing verb is implied from the mailing name, in the above example the verb is :new_enquiry
|
42
42
|
|
43
|
-
The act_object may be the entity performing the
|
43
|
+
The act_object may be the entity performing the mailing, or the entity on which the mailing was performed.
|
44
44
|
e.g John(actor) shared a video(act_object)
|
45
45
|
|
46
46
|
The target is the act_object that the verb is enacted on.
|
@@ -69,18 +69,18 @@ In your controller or background worker:
|
|
69
69
|
current_user.send_email(:new_enquiry, :act_object => @enquiry, :target => @listing)
|
70
70
|
```
|
71
71
|
|
72
|
-
This will publish the
|
72
|
+
This will publish the mailing to the mongoid act_objects returned by the #followers method in the Actor.
|
73
73
|
|
74
74
|
|
75
75
|
## Retrieving LoggedEmail
|
76
76
|
|
77
|
-
To retrieve all
|
77
|
+
To retrieve all mailing for an actor
|
78
78
|
|
79
79
|
``` ruby
|
80
80
|
current_user.logged_emails
|
81
81
|
```
|
82
82
|
|
83
|
-
To retrieve and filter to a particular
|
83
|
+
To retrieve and filter to a particular mailing type
|
84
84
|
|
85
85
|
``` ruby
|
86
86
|
current_user.logged_emails(:verb => 'new_enquiry')
|
@@ -94,7 +94,7 @@ Additional options can be required:
|
|
94
94
|
class LoggedEmail < ActiveRecord::Base
|
95
95
|
include MailControl::LoggedEmail
|
96
96
|
|
97
|
-
|
97
|
+
mailing :new_enquiry do
|
98
98
|
actor :User
|
99
99
|
act_object :Article
|
100
100
|
act_target :Volume
|
@@ -110,13 +110,13 @@ The option fields are stored using the ActiveRecord 'store' feature.
|
|
110
110
|
#### Bond type
|
111
111
|
|
112
112
|
A verb can have one bond type. This bond type can be used to classify and quickly retrieve
|
113
|
-
|
113
|
+
mailing feed items that belong to a particular aggregate feed, like e.g the global feed.
|
114
114
|
|
115
115
|
``` ruby
|
116
116
|
class LoggedEmail < ActiveRecord::Base
|
117
117
|
include MailControl::LoggedEmail
|
118
118
|
|
119
|
-
|
119
|
+
mailing :new_enquiry do
|
120
120
|
actor :User
|
121
121
|
act_object :Article
|
122
122
|
act_target :Volume
|
@@ -7,7 +7,7 @@ module MailControl
|
|
7
7
|
module Base
|
8
8
|
# Get path for migration template
|
9
9
|
def source_root
|
10
|
-
@_mail_control_source_root ||= File.expand_path(File.join('../
|
10
|
+
@_mail_control_source_root ||= File.expand_path(File.join('../mail_control', generator_name, 'templates'), __FILE__)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
data/lib/generators/{mail-control/activity → mail_control/logged_email}/activity_generator.rb
RENAMED
@@ -1,9 +1,9 @@
|
|
1
|
-
require 'generators/
|
1
|
+
require 'generators/mail_control'
|
2
2
|
require 'rails/generators/active_record'
|
3
3
|
|
4
4
|
module MailControl
|
5
5
|
module Generators
|
6
|
-
# LoggedEmail generator that creates
|
6
|
+
# LoggedEmail generator that creates mailing model file from template
|
7
7
|
class LoggedEmailGenerator < ActiveRecord::Generators::Base
|
8
8
|
extend Base
|
9
9
|
|
data/lib/generators/{mail-control/activity → mail_control/logged_email}/templates/logged_email.rb
RENAMED
File without changes
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require 'generators/
|
1
|
+
require 'generators/mail_control'
|
2
2
|
require 'rails/generators/active_record'
|
3
3
|
|
4
|
-
module
|
4
|
+
module MailControl
|
5
5
|
module Generators
|
6
6
|
# Migration generator that creates migration file from template
|
7
7
|
class MigrationGenerator < ActiveRecord::Generators::Base
|
File without changes
|
data/lib/mail-control/actor.rb
CHANGED
@@ -4,7 +4,7 @@ module MailControl
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
cattr_accessor :
|
7
|
+
cattr_accessor :mailing_klass
|
8
8
|
|
9
9
|
has_many :logged_emails, :class_name => "LoggedEmail", :as => :actor
|
10
10
|
has_many :act_object_logged_emails, :class_name => "LoggedEmail", :as => :act_object
|
@@ -16,17 +16,17 @@ module MailControl
|
|
16
16
|
module ClassMethods
|
17
17
|
|
18
18
|
def mail_control_class(klass)
|
19
|
-
self.
|
19
|
+
self.mailing_klass = klass.to_s
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
23
23
|
|
24
24
|
|
25
|
-
# Publishes the
|
25
|
+
# Publishes the mailing to the receivers
|
26
26
|
#
|
27
27
|
# @param [ Hash ] options The options to publish with.
|
28
28
|
#
|
29
|
-
# @example publish an
|
29
|
+
# @example publish an mailing with a act_object and act_target
|
30
30
|
# current_user.send_email(:enquiry, :act_object => @enquiry, :act_target => @listing)
|
31
31
|
#
|
32
32
|
def send_email(name, options={})
|
@@ -40,7 +40,7 @@ module MailControl
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def mail_control_class
|
43
|
-
@
|
43
|
+
@mailing_klass ||= mailing_klass ? mailing_klass.classify.constantize : ::LoggedEmail
|
44
44
|
end
|
45
45
|
|
46
46
|
def actor_logged_emails(options = {})
|
@@ -42,26 +42,26 @@ module MailControl
|
|
42
42
|
|
43
43
|
# Defines a new LoggedEmail2 type and registers a definition
|
44
44
|
#
|
45
|
-
# @param [ String ] name The name of the
|
45
|
+
# @param [ String ] name The name of the mailing
|
46
46
|
#
|
47
|
-
# @example Define a new
|
48
|
-
#
|
47
|
+
# @example Define a new mailing
|
48
|
+
# mailing(:enquiry) do
|
49
49
|
# actor :user, :cache => [:full_name]
|
50
50
|
# act_object :enquiry, :cache => [:subject]
|
51
51
|
# act_target :listing, :cache => [:title]
|
52
52
|
# end
|
53
53
|
#
|
54
54
|
# @return [Definition] Returns the registered definition
|
55
|
-
def
|
55
|
+
def mailing(name, &block)
|
56
56
|
definition = MailControl::DefinitionDSL.new(name)
|
57
57
|
definition.instance_eval(&block)
|
58
58
|
MailControl::Definition.register(definition)
|
59
59
|
end
|
60
60
|
|
61
|
-
# Publishes an
|
61
|
+
# Publishes an mailing using an mailing name and data
|
62
62
|
#
|
63
|
-
# @param [ String ] verb The verb of the
|
64
|
-
# @param [ Hash ] data The data to initialize the
|
63
|
+
# @param [ String ] verb The verb of the mailing
|
64
|
+
# @param [ Hash ] data The data to initialize the mailing with.
|
65
65
|
#
|
66
66
|
# @return [MailControl::LoggedEmail2] An LoggedEmail instance with data
|
67
67
|
def send_email(verb, data)
|
@@ -72,7 +72,7 @@ module MailControl
|
|
72
72
|
|
73
73
|
|
74
74
|
|
75
|
-
# Publishes the
|
75
|
+
# Publishes the mailing to the receivers
|
76
76
|
#
|
77
77
|
# @param [ Hash ] options The options to send_email with.
|
78
78
|
#
|
data/lib/mail-control/version.rb
CHANGED
data/mail-control.gemspec
CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.summary = %q{LoggedEmail Streams for rails}
|
12
12
|
s.description = %q{MailControl is a simple gem for giving both your app and users control over when, if and how emails are sent out.}
|
13
13
|
s.homepage = 'https://github.com/digitalplaywright/mail-control'
|
14
|
+
s.license = 'MIT'
|
14
15
|
|
15
16
|
s.rubyforge_project = "mail-control"
|
16
17
|
|
data/test/test_helper.rb
CHANGED
@@ -26,7 +26,7 @@ end
|
|
26
26
|
class LoggedEmail < ActiveRecord::Base
|
27
27
|
include MailControl::LoggedEmail
|
28
28
|
|
29
|
-
|
29
|
+
mailing :new_enquiry do
|
30
30
|
actor :User
|
31
31
|
act_object :Article
|
32
32
|
act_target :User
|
@@ -34,7 +34,7 @@ class LoggedEmail < ActiveRecord::Base
|
|
34
34
|
unsubscribe_by :option_1
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
mailing :test_description do
|
38
38
|
actor :User
|
39
39
|
act_object :Article
|
40
40
|
act_target :User
|
@@ -42,7 +42,7 @@ class LoggedEmail < ActiveRecord::Base
|
|
42
42
|
unsubscribe_by :option_1
|
43
43
|
end
|
44
44
|
|
45
|
-
|
45
|
+
mailing :test_option do
|
46
46
|
actor :User
|
47
47
|
act_object :Article
|
48
48
|
act_target :User
|
@@ -50,7 +50,7 @@ class LoggedEmail < ActiveRecord::Base
|
|
50
50
|
unsubscribe_by :option_1
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
mailing :test_bond_type do
|
54
54
|
actor :User
|
55
55
|
act_object :Article
|
56
56
|
act_target :User
|
data/test/unit/activity_test.rb
CHANGED
@@ -6,7 +6,7 @@ class LoggedEmailTest < ActiveSupport::TestCase
|
|
6
6
|
|
7
7
|
def test_register_definition
|
8
8
|
|
9
|
-
@definition = LoggedEmail.
|
9
|
+
@definition = LoggedEmail.mailing(:test_mailing) do
|
10
10
|
actor :user, :cache => [:full_name]
|
11
11
|
act_object :listing, :cache => [:title, :full_address]
|
12
12
|
act_target :listing, :cache => [:title]
|
@@ -16,15 +16,15 @@ class LoggedEmailTest < ActiveSupport::TestCase
|
|
16
16
|
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def test_publish_new_mailing
|
20
20
|
_user = User.create()
|
21
21
|
_article = Article.create()
|
22
22
|
_user_t = User.create()
|
23
23
|
|
24
|
-
|
24
|
+
_mailing = LoggedEmail.send_email(:new_enquiry, :send_after => Time.now, :send_before => Time.now + 1.hour, :actor => _user, :act_object => _article, :act_target => _user_t )
|
25
25
|
|
26
|
-
assert
|
27
|
-
#
|
26
|
+
assert _mailing.persisted?
|
27
|
+
#_mailing.should be_an_instance_of LoggedEmail
|
28
28
|
|
29
29
|
end
|
30
30
|
|
@@ -34,10 +34,10 @@ class LoggedEmailTest < ActiveSupport::TestCase
|
|
34
34
|
_user_t = User.create()
|
35
35
|
|
36
36
|
_description = "this is a test"
|
37
|
-
|
37
|
+
_mailing = LoggedEmail.send_email(:test_description, :send_after => Time.now, :send_before => Time.now + 1.hour, :actor => _user, :act_object => _article, :act_target => _user_t ,
|
38
38
|
:description => _description )
|
39
39
|
|
40
|
-
assert
|
40
|
+
assert _mailing.description == _description
|
41
41
|
|
42
42
|
end
|
43
43
|
|
@@ -47,10 +47,10 @@ class LoggedEmailTest < ActiveSupport::TestCase
|
|
47
47
|
_user_t = User.create()
|
48
48
|
|
49
49
|
_country = "denmark"
|
50
|
-
|
50
|
+
_mailing = LoggedEmail.send_email(:test_option, :send_after => Time.now, :send_before => Time.now + 1.hour, :actor => _user, :act_object => _article, :act_target => _user_t ,
|
51
51
|
:country => _country )
|
52
52
|
|
53
|
-
assert
|
53
|
+
assert _mailing.options[:country] == _country
|
54
54
|
|
55
55
|
end
|
56
56
|
|
@@ -59,9 +59,9 @@ class LoggedEmailTest < ActiveSupport::TestCase
|
|
59
59
|
_article = Article.create()
|
60
60
|
_user_t = User.create()
|
61
61
|
|
62
|
-
|
62
|
+
_mailing = LoggedEmail.send_email(:test_bond_type, :send_after => Time.now, :send_before => Time.now + 1.hour, :actor => _user, :act_object => _article, :act_target => _user_t )
|
63
63
|
|
64
|
-
assert
|
64
|
+
assert _mailing.bond_type == 'global'
|
65
65
|
|
66
66
|
end
|
67
67
|
|
data/test/unit/actor_test.rb
CHANGED
@@ -7,9 +7,9 @@ class ActorTest < ActiveSupport::TestCase
|
|
7
7
|
_article = Article.create()
|
8
8
|
_user_t = User.create()
|
9
9
|
|
10
|
-
|
10
|
+
mailing = _user.send_email(:new_enquiry, :send_after => Time.now, :send_before => Time.now + 1.hour, :act_object => _article, :act_target => _user_t )
|
11
11
|
|
12
|
-
assert
|
12
|
+
assert mailing.persisted?
|
13
13
|
|
14
14
|
end
|
15
15
|
|
@@ -26,7 +26,7 @@ class ActorTest < ActiveSupport::TestCase
|
|
26
26
|
end
|
27
27
|
|
28
28
|
|
29
|
-
def
|
29
|
+
def test_retrieves_the_stream_for_a_particular_mailing_type
|
30
30
|
_user = User.create()
|
31
31
|
_article = Article.create()
|
32
32
|
_user_t = User.create()
|
@@ -42,9 +42,9 @@ class DefinitionTest < ActiveSupport::TestCase
|
|
42
42
|
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
45
|
+
def test_raise_exception_if_invalid_mailing
|
46
46
|
|
47
|
-
assert_raises(MailControl::InvalidLoggedEmail){ MailControl::Definition.find(:
|
47
|
+
assert_raises(MailControl::InvalidLoggedEmail){ MailControl::Definition.find(:unknown_mailing) }
|
48
48
|
|
49
49
|
end
|
50
50
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail-control
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Saebjoernsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -83,11 +83,11 @@ files:
|
|
83
83
|
- LICENSE.txt
|
84
84
|
- README.md
|
85
85
|
- Rakefile
|
86
|
-
- lib/generators/
|
87
|
-
- lib/generators/
|
88
|
-
- lib/generators/
|
89
|
-
- lib/generators/
|
90
|
-
- lib/generators/
|
86
|
+
- lib/generators/mail_control.rb
|
87
|
+
- lib/generators/mail_control/logged_email/activity_generator.rb
|
88
|
+
- lib/generators/mail_control/logged_email/templates/logged_email.rb
|
89
|
+
- lib/generators/mail_control/migration/migration_generator.rb
|
90
|
+
- lib/generators/mail_control/migration/templates/migration.rb
|
91
91
|
- lib/mail-control.rb
|
92
92
|
- lib/mail-control/actor.rb
|
93
93
|
- lib/mail-control/definition.rb
|
@@ -107,7 +107,8 @@ files:
|
|
107
107
|
- test/unit/definition_dsl_test.rb
|
108
108
|
- test/unit/definition_test.rb
|
109
109
|
homepage: https://github.com/digitalplaywright/mail-control
|
110
|
-
licenses:
|
110
|
+
licenses:
|
111
|
+
- MIT
|
111
112
|
metadata: {}
|
112
113
|
post_install_message:
|
113
114
|
rdoc_options: []
|