ahoy_email 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c93fae59edb3ef7d69664769d7706673c09955ca
4
- data.tar.gz: d4fcf110e9b0d31f27df464426c5b98ecd8c68a5
3
+ metadata.gz: fe2130c231eb69814fa0ad0f3afd38560b7186e9
4
+ data.tar.gz: 83cd45ecac4cd1345c49c0e798c23cfcc4eb646d
5
5
  SHA512:
6
- metadata.gz: 3c3be760d8cd4b4bbbb4d7f7c82124f0243b3234a0019a9bd041241cb0ca04c2880ed539e9f0868f248c2c1d6c45cc4cf06845e97c563b26b8d19ca6ebb91a28
7
- data.tar.gz: e76a54879f082d10651fed3e82c3dcb969eb1fd7ca3bcca9b7ab46214e73152a244ce598ecd5b71165ace8b1867bc4baa65577537a1e998db2458c58df325025
6
+ metadata.gz: 310069adf7575599950544584a1452ea43557862cb0e692191d5ea4b9132b9681681fa8dd62d87a75d1072d5e6ba92ee0848ac7b8183d5100335d355b3fce102
7
+ data.tar.gz: 6304688a168126a1d6af7d6a92a17cc830488f2109ade62bf092022895c22f1314365cec25e53ccd556a9134f1bb1c534bac8fb998d7eb0d804a25fb4b1d9c1f
@@ -1,3 +1,7 @@
1
+ ## 0.2.1
2
+
3
+ - Added `only` and `except` options
4
+
1
5
  ## 0.2.0
2
6
 
3
7
  - Enable tracking when track is called by default
data/README.md CHANGED
@@ -116,9 +116,20 @@ Use `track utm_params: false` to skip tagging, or skip specific links with:
116
116
 
117
117
  ## Customize
118
118
 
119
+ ### Tracking
120
+
121
+ Skip tracking of attributes by removing them from your model. You can safely remove:
122
+
123
+ - to
124
+ - mailer
125
+ - subject
126
+ - content
127
+
128
+ ### Configuration
129
+
119
130
  There are 3 places to set options. Here’s the order of precedence.
120
131
 
121
- ### Action
132
+ #### Action
122
133
 
123
134
  ``` ruby
124
135
  class UserMailer < ActionMailer::Base
@@ -130,7 +141,7 @@ class UserMailer < ActionMailer::Base
130
141
  end
131
142
  ```
132
143
 
133
- ### Mailer
144
+ #### Mailer
134
145
 
135
146
  ```ruby
136
147
  class UserMailer < ActionMailer::Base
@@ -138,7 +149,7 @@ class UserMailer < ActionMailer::Base
138
149
  end
139
150
  ```
140
151
 
141
- ### Global
152
+ #### Global
142
153
 
143
154
  ```ruby
144
155
  AhoyEmail.track open: false
@@ -182,6 +193,13 @@ Disable tracking for an email
182
193
  track message: false
183
194
  ```
184
195
 
196
+ Or specific actions
197
+
198
+ ```ruby
199
+ track only: [:welcome_email]
200
+ track except: [:welcome_email]
201
+ ```
202
+
185
203
  Or by default
186
204
 
187
205
  ```ruby
@@ -4,6 +4,7 @@ module AhoyEmail
4
4
  def self.included(base)
5
5
  base.extend ClassMethods
6
6
  base.class_eval do
7
+ attr_accessor :ahoy_options
7
8
  class_attribute :ahoy_options
8
9
  self.ahoy_options = {}
9
10
  alias_method_chain :mail, :ahoy
@@ -11,26 +12,18 @@ module AhoyEmail
11
12
  end
12
13
 
13
14
  module ClassMethods
14
- def track(options)
15
+ def track(options = {})
15
16
  self.ahoy_options = ahoy_options.merge(message: true).merge(options)
16
17
  end
17
18
  end
18
19
 
19
- def track(options)
20
- @ahoy_options = (@ahoy_options || {}).merge(message: true).merge(options)
20
+ def track(options = {})
21
+ self.ahoy_options = (ahoy_options || {}).merge(message: true).merge(options)
21
22
  end
22
23
 
23
24
  def mail_with_ahoy(headers = {}, &block)
24
25
  message = mail_without_ahoy(headers, &block)
25
-
26
- options = AhoyEmail.options.merge(self.class.ahoy_options).merge(@ahoy_options || {})
27
- options.each do |k, v|
28
- if v.respond_to?(:call)
29
- options[k] = v.call(message, self)
30
- end
31
- end
32
- AhoyEmail::Processor.new(message, options).process
33
-
26
+ AhoyEmail::Processor.new(message, self).process
34
27
  message
35
28
  end
36
29
 
@@ -1,14 +1,15 @@
1
1
  module AhoyEmail
2
2
  class Processor
3
- attr_reader :message, :options, :ahoy_message
3
+ attr_reader :message, :mailer, :ahoy_message
4
4
 
5
- def initialize(message, options = {})
5
+ def initialize(message, mailer = nil)
6
6
  @message = message
7
- @options = options
7
+ @mailer = mailer
8
8
  end
9
9
 
10
10
  def process
11
- if options[:message]
11
+ action_name = mailer.action_name.to_sym
12
+ if options[:message] and (!options[:only] or options[:only].include?(action_name)) and !options[:except].to_a.include?(action_name)
12
13
  @ahoy_message = AhoyEmail.message_model.new
13
14
  ahoy_message.token = generate_token
14
15
  ahoy_message.to = message.to.join(", ") if ahoy_message.respond_to?(:to=)
@@ -43,6 +44,21 @@ module AhoyEmail
43
44
 
44
45
  protected
45
46
 
47
+ def options
48
+ @options ||= begin
49
+ options = AhoyEmail.options.merge(mailer.class.ahoy_options)
50
+ if mailer.ahoy_options
51
+ options = options.except(:only, :except).merge(mailer.ahoy_options)
52
+ end
53
+ options.each do |k, v|
54
+ if v.respond_to?(:call)
55
+ options[k] = v.call(message, mailer)
56
+ end
57
+ end
58
+ options
59
+ end
60
+ end
61
+
46
62
  def generate_token
47
63
  SecureRandom.urlsafe_base64(32).gsub(/[\-_]/, "").first(32)
48
64
  end
@@ -1,3 +1,3 @@
1
1
  module AhoyEmail
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ahoy_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-11 00:00:00.000000000 Z
11
+ date: 2014-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails