digestifier 0.0.2 → 0.0.3

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: d3a5586226e9c9c2d3873fa148109906568a72bd
4
- data.tar.gz: f0028131bb564be48fb02c89914559727834f6fd
3
+ metadata.gz: bc2bff6ead8753dd54d921694f2b63d050a75c04
4
+ data.tar.gz: e12e3a4577b2402543f642a8f912fb391888d9e8
5
5
  SHA512:
6
- metadata.gz: ae5bb559b00b5e577bf18a91f16398abe0dca5a330806cf553764c44fbc79af499aa54cc72c1e45e7e10e82ccb7ad2707c565aae63da26bb955f34dca7412fa7
7
- data.tar.gz: cd7b5a66c3e5592c834ce79380d28ded690e079a36e80814af27a77d1b78f1f3243c14211980a94fa5708398f70b6fb1984a5f46afddef32dca271df9b6f57e0
6
+ metadata.gz: 0caf0b5098f15efe9f3c3778a45e67c6fa981f9e35f7623023c8dfb80c1e5828f5938ae1d2f2d9563e07e2f27b1b304b09f68c2169334325327b3c5266d6f803
7
+ data.tar.gz: d8a0bc60a634fde41e4cfdd03f36d71d4ce606647df4f3fd954706ab9001bef5a5073626b22bfd5cef71b0e38116942d65a87691b03cc99f820667956561cfe9
data/README.md CHANGED
@@ -6,7 +6,7 @@ A simple Rails engine for sending out email digests of activity.
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'digestifier', '0.0.2'
9
+ gem 'digestifier', '0.0.3'
10
10
 
11
11
  Don't forget to bundle:
12
12
 
@@ -58,6 +58,12 @@ task :send_digest => :environment do
58
58
  end
59
59
  ```
60
60
 
61
+ You can test sending an email to a specific recipient using the following code:
62
+
63
+ ```ruby
64
+ Digestifier::Delivery.new(DIGEST, recipient).deliver
65
+ ```
66
+
61
67
  ### Customising partial templates
62
68
 
63
69
  This step is almost certainly essential: you'll want to customise how each item in your digest is presented. The partials for this should be located in `app/views/digestifier/mailer`, and use the item's class name, downcased and underscored (for example: `_article.html.erb` or `_comment.html.haml`).
@@ -82,6 +88,16 @@ The two instance variables you have access to are `@recipient` and `@content_ite
82
88
  <% end %>
83
89
  ```
84
90
 
91
+ Also: you'll very likely want to customise the email's subject - this is done via Rails' internationalisation:
92
+
93
+ ```yaml
94
+ en:
95
+ digestifier:
96
+ mailer:
97
+ digest:
98
+ subject: "The Latest News"
99
+ ```
100
+
85
101
  ### Customising the mailer
86
102
 
87
103
  If you want to put your own Mailer, then this is certainly possible:
@@ -5,8 +5,7 @@ class Digestifier::Setting < ActiveRecord::Base
5
5
 
6
6
  serialize :preferences, JSON
7
7
 
8
- validates :recipient, presence: true
9
- validates :preferences, presence: true
8
+ validates :recipient, presence: true
10
9
 
11
10
  def self.for(recipient)
12
11
  where(
@@ -0,0 +1,6 @@
1
+ class AddEnabledToSettings < ActiveRecord::Migration
2
+ def change
3
+ add_column :digestifier_settings, :enabled, :boolean, default: true,
4
+ null: false
5
+ end
6
+ end
data/digestifier.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = 'digestifier'
4
- spec.version = '0.0.2'
4
+ spec.version = '0.0.3'
5
5
  spec.authors = ['Pat Allan']
6
6
  spec.email = ['pat@freelancing-gods.com']
7
7
  spec.summary = 'Digests as a Rails Engine'
@@ -1,7 +1,7 @@
1
1
  class Digestifier::Delivery
2
2
  def self.deliver(digest)
3
3
  digest.recipients.call.find_each do |recipient|
4
- new(digest, recipient).deliver
4
+ new(digest, recipient).deliver_and_capture
5
5
  end
6
6
  end
7
7
 
@@ -9,9 +9,19 @@ class Digestifier::Delivery
9
9
  @digest, @recipient = digest, recipient
10
10
  end
11
11
 
12
+ def capture
13
+ Digestifier::Receipt.capture recipient
14
+ end
15
+
12
16
  def deliver
17
+ return unless settings.enabled?
18
+
13
19
  Digestifier.mailer.digest(recipient, contents).deliver
14
- Digestifier::Receipt.capture recipient
20
+ end
21
+
22
+ def deliver_and_capture
23
+ deliver
24
+ capture
15
25
  end
16
26
 
17
27
  private
@@ -25,7 +35,6 @@ class Digestifier::Delivery
25
35
  end
26
36
 
27
37
  def frequency
28
- settings = Digestifier::Setting.for recipient
29
38
  return default_frequency unless settings.preferences['frequency']
30
39
 
31
40
  settings.preferences['frequency']
@@ -35,4 +44,8 @@ class Digestifier::Delivery
35
44
  receipt = Digestifier::Receipt.last_for(recipient)
36
45
  receipt.nil? ? frequency.ago : receipt.captured_at
37
46
  end
47
+
48
+ def settings
49
+ @settings ||= Digestifier::Setting.for recipient
50
+ end
38
51
  end
@@ -29,4 +29,18 @@ describe 'Custom digest frequency' do
29
29
  expect(mail.body).to match(/Recent Post/)
30
30
  expect(mail.body).to_not match(/Old Post/)
31
31
  end
32
+
33
+ it 'respects disabled digest preferences' do
34
+ Article.create! name: 'Recent Post'
35
+
36
+ setting = Digestifier::Setting.for(user)
37
+ setting.enabled = false
38
+ setting.save!
39
+
40
+ Digestifier::Delivery.deliver digest
41
+
42
+ ActionMailer::Base.deliveries.detect { |mail|
43
+ mail.to.include?('me@somewhere.com')
44
+ }.should be_nil
45
+ end
32
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: digestifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-09 00:00:00.000000000 Z
11
+ date: 2013-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -88,6 +88,7 @@ files:
88
88
  - config.ru
89
89
  - db/migrate/1_create_receipts.rb
90
90
  - db/migrate/2_create_settings.rb
91
+ - db/migrate/3_add_enabled_to_settings.rb
91
92
  - digestifier.gemspec
92
93
  - lib/digestifier.rb
93
94
  - lib/digestifier/delivery.rb