tricle 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ab31c91268e7d383dbc8090108459f7359d9d94
4
- data.tar.gz: 2408d69e0b97e949ff16e572eece95f8ceca80c0
3
+ metadata.gz: b642f05f1b01ca4cd31ea2686d60ef99e63d203a
4
+ data.tar.gz: c230338123cff716fa9951ec7a2973c059448df3
5
5
  SHA512:
6
- metadata.gz: ef63f1335cb81ca70af935ae1e495b0a2f78c260f7ca7a02a232de3f059dc267b40505ff99d4f10d89fa704420154ae309f9f8ad253570321cc1e0caff5ee649
7
- data.tar.gz: f2eadcb789c8caf60fa2a1446740646831898eea9f734856c03f1355844628ef46fefc3a10bd93c5e6669649a48111572571bd3a54bdb5df8e419b3999dc8145
6
+ metadata.gz: 2ca75aae8ba3b852f2983e4444ba970959586be2209c4dc08209c7a5a0b3910d97e6d0982a0251a7aa7bb7b259c8c886b0d9af8ff8d765a6b53b6ad069543a7b
7
+ data.tar.gz: 59a2a220783e513ee84e8d650d213779dbc16735bdbbd7920b386d926b0caa6ff232438989fdf5720410680f8680504ad1101aabe9f4e1ec8f98dc2f7b69c365
data/README.md CHANGED
@@ -6,23 +6,29 @@ Automated metrics reporting via email. It's datastore-agnostic, so you can quer
6
6
 
7
7
  ## Installation
8
8
 
9
- ### Gem
10
-
11
9
  This gem can be used within an existing project (e.g. a Rails app), or standalone.
12
10
 
13
11
  ```ruby
14
12
  # Gemfile
15
13
  gem 'tricle', '~> 0.2.0'
16
14
 
15
+
17
16
  # Rakefile
17
+ require 'your/tricle/subclasses'
18
18
  require 'tricle/tasks'
19
19
 
20
+
20
21
  # your/config/file.rb
22
+
21
23
  # unless you already have ActionMailer set up
22
24
  ActionMailer::Base.raise_delivery_errors = true
23
25
  ActionMailer::Base.smtp_settings = {
24
26
  # ...
25
27
  }
28
+
29
+ # Optional: Override the start day of the reports (Rails >= 4.0.3 only)
30
+ # http://api.rubyonrails.org/classes/Date.html#method-i-beginning_of_week-3D
31
+ Date.beginning_of_week = :monday
26
32
  ```
27
33
 
28
34
  See [the ActionMailer guide](http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration) for configuration details. Finally, execute:
@@ -237,6 +243,21 @@ To set a speficic time zone, use the `TZ` environment variable (see the list [he
237
243
  TZ=UTC rake tricle:emails:send
238
244
  ```
239
245
 
240
- ### Cron Setup
246
+ ### Heroku
247
+
248
+ 1. Deploy the application.
249
+ * If this is a standalone app, you won't need a `web` process.
250
+ 1. Enable an [add-on for email delivery](https://addons.heroku.com/?q=email%20deliver), and [configure](#installation) ActionMailer to send via that provider.
251
+ 1. Enable [Heroku Scheduler](https://devcenter.heroku.com/articles/scheduler).
252
+
253
+ ```bash
254
+ heroku addons:add scheduler:standard
255
+ heroku addons:open scheduler
256
+ ```
257
+
258
+ 1. Add a "job".
259
+ * For a report sent once per day, use the command from [Deploying](#deploying).
260
+ * For a report sent once per week, use `rake tricle:emails:send_after_beginning_of_week` daily.
261
+ * Heroku Scheduler only supports a maximum of daily tasks, hence needing to use a special task.
241
262
 
242
- TODO
263
+ You can trigger the email(s) manually for testing with `heroku run rake tricle:emails:send`.
@@ -4,6 +4,7 @@ require 'premailer'
4
4
 
5
5
  require_relative 'email_helper'
6
6
  require_relative 'presenters/report'
7
+ require_relative 'time'
7
8
 
8
9
 
9
10
  module Tricle
@@ -70,6 +71,15 @@ module Tricle
70
71
  end
71
72
  puts "Done."
72
73
  end
74
+
75
+ def send_all_if_beginning_of_week
76
+ time = Tricle::Time.new
77
+ if time.beginning_of_week?
78
+ self.send_all
79
+ else
80
+ puts "Skipping send, because it's not the beginning of the week."
81
+ end
82
+ end
73
83
  end
74
84
  end
75
85
  end
@@ -10,7 +10,7 @@ module Tricle
10
10
  attr_reader :now, :options
11
11
 
12
12
  def initialize(opts = {})
13
- @now = opts[:now] || Time.now
13
+ @now = Tricle::Time.new(opts[:now])
14
14
  @options = opts
15
15
  end
16
16
 
@@ -15,5 +15,11 @@ namespace :tricle do
15
15
  task :send do
16
16
  Tricle::Mailer.send_all
17
17
  end
18
+
19
+ # needed for Heroku Scheduler, whose most infrequent option is daily
20
+ desc "Send all emails, but only if it's the current day is the \"beginning of the week\". See http://api.rubyonrails.org/classes/Date.html#method-i-beginning_of_week-3D."
21
+ task :send_after_beginning_of_week do
22
+ Tricle::Mailer.send_all_if_beginning_of_week
23
+ end
18
24
  end
19
25
  end
@@ -0,0 +1,41 @@
1
+ module Tricle
2
+ class Time
3
+ attr_reader :time
4
+
5
+ def initialize(time=nil)
6
+ @time = time || ::Time.now
7
+ end
8
+
9
+ def day_of_week
10
+ self.time.strftime('%A').downcase.to_sym
11
+ end
12
+
13
+ def beginning_of_week?
14
+ self.day_of_week == self.class.beginning_of_week
15
+ end
16
+
17
+ ## delegate methods ##
18
+
19
+ def beginning_of_day
20
+ self.time.beginning_of_day
21
+ end
22
+
23
+ def beginning_of_week
24
+ self.time.beginning_of_week
25
+ end
26
+
27
+ ######################
28
+
29
+ class << self
30
+ def beginning_of_week
31
+ if Date.respond_to?(:beginning_of_week)
32
+ # Rails >= 4.0.2
33
+ # http://apidock.com/rails/v4.0.2/Date/beginning_of_week/class
34
+ Date.beginning_of_week
35
+ else
36
+ :monday
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module Tricle
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -2,6 +2,7 @@ require 'timecop'
2
2
 
3
3
  def reset_time
4
4
  # need to freeze the time for the TestMetric
5
+ # 1AM, Thursday, August 1, 2013
5
6
  now = Time.new(2013, 8, 1, 1, 0, 0)
6
7
  Timecop.freeze(now)
7
8
  end
@@ -76,4 +76,17 @@ describe Tricle::Mailer do
76
76
  expect(ActionMailer::Base.deliveries.length).to eq(5)
77
77
  end
78
78
  end
79
+
80
+ describe '.send_all_if_beginning_of_week' do
81
+ it "shouldn't do anything if not the beginning of the week" do
82
+ expect(Tricle::Mailer).to_not receive(:send_all)
83
+ Tricle::Mailer.send_all_if_beginning_of_week
84
+ end
85
+
86
+ it "should send if it's the beginning of the week" do
87
+ Timecop.freeze(Time.now - 3.days) # Monday
88
+ expect(Tricle::Mailer).to receive(:send_all)
89
+ Tricle::Mailer.send_all_if_beginning_of_week
90
+ end
91
+ end
79
92
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tricle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aidan Feldman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-05 00:00:00.000000000 Z
11
+ date: 2014-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -129,6 +129,7 @@ files:
129
129
  - lib/tricle/templates/email.css
130
130
  - lib/tricle/templates/email.html.erb
131
131
  - lib/tricle/templates/email.text.erb
132
+ - lib/tricle/time.rb
132
133
  - lib/tricle/version.rb
133
134
  - screenshot.png
134
135
  - spec/app/group_test_mailer.rb