jzimmek-reportme 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.
- data/VERSION +1 -1
- data/lib/reportme/report_factory.rb +21 -20
- data/test/reportme_test.rb +36 -13
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
@@ -4,30 +4,21 @@ require 'reportme/mailer'
|
|
4
4
|
module Reportme
|
5
5
|
class ReportFactory
|
6
6
|
|
7
|
-
def self.create(
|
8
|
-
rme = ReportFactory.new
|
7
|
+
def self.create(&block)
|
8
|
+
rme = ReportFactory.new
|
9
9
|
rme.instance_eval(&block)
|
10
|
-
rme.connect
|
11
|
-
rme.run
|
12
10
|
rme
|
13
11
|
end
|
14
12
|
|
15
|
-
def initialize
|
16
|
-
raise "since cannot be in the future" if since.future?
|
17
|
-
|
13
|
+
def initialize
|
18
14
|
@reports = []
|
19
|
-
@since = since.to_date
|
20
15
|
@subscribtions = {}
|
21
16
|
@report_exists_cache = []
|
22
|
-
@mailserver = nil
|
23
|
-
end
|
24
|
-
|
25
|
-
def connect
|
26
|
-
ActiveRecord::Base.establish_connection(@properties)
|
27
17
|
end
|
28
18
|
|
29
19
|
def connection(properties)
|
30
20
|
@properties = properties
|
21
|
+
ActiveRecord::Base.establish_connection(@properties)
|
31
22
|
end
|
32
23
|
|
33
24
|
def smtp(settings)
|
@@ -38,18 +29,28 @@ module Reportme
|
|
38
29
|
Mailer.deliver_message(from, recipients, subject, body, attachments)
|
39
30
|
end
|
40
31
|
|
41
|
-
def
|
32
|
+
def since(since)
|
33
|
+
raise "since has already been set to '#{@since}' and cannot be changed to: '#{since}'" if @since
|
34
|
+
raise "since cannot be in the future" if since.future?
|
42
35
|
|
36
|
+
@since = since.to_date
|
37
|
+
end
|
38
|
+
|
39
|
+
def init(&block)
|
43
40
|
raise "only one init block allowed" if @init
|
44
|
-
|
45
41
|
@init = block;
|
46
42
|
end
|
47
43
|
|
48
|
-
def self.periods(today
|
44
|
+
def self.periods(today)
|
49
45
|
|
50
46
|
r = []
|
47
|
+
p = []
|
48
|
+
|
49
|
+
# period "today" will never be generated for previous days
|
50
|
+
p << :today if today.to_date == Date.today
|
51
|
+
p += [:day, :week, :calendar_week, :month, :calendar_month]
|
51
52
|
|
52
|
-
|
53
|
+
p.each do |period|
|
53
54
|
|
54
55
|
von, bis = case period
|
55
56
|
when :today
|
@@ -123,7 +124,7 @@ module Reportme
|
|
123
124
|
@report_exists_cache.clear
|
124
125
|
exec("drop table if exists #{report_information_table_name};")
|
125
126
|
|
126
|
-
ReportFactory.periods.each do |period|
|
127
|
+
ReportFactory.periods(@since).each do |period|
|
127
128
|
@reports.each do |r|
|
128
129
|
exec("drop table if exists #{r.table_name(period[:name])};")
|
129
130
|
end
|
@@ -192,7 +193,8 @@ module Reportme
|
|
192
193
|
|
193
194
|
def run
|
194
195
|
|
195
|
-
@init.call
|
196
|
+
@init.call if @init
|
197
|
+
@since = Date.today unless @since
|
196
198
|
|
197
199
|
ensure_report_informations_table_exist
|
198
200
|
|
@@ -205,7 +207,6 @@ module Reportme
|
|
205
207
|
@since += 1.day
|
206
208
|
end
|
207
209
|
|
208
|
-
|
209
210
|
# we will generate all daily reports first.
|
210
211
|
# this will speed up generation of weekly and monthly reports.
|
211
212
|
|
data/test/reportme_test.rb
CHANGED
@@ -26,8 +26,9 @@ class ReportmeTest < Test::Unit::TestCase
|
|
26
26
|
|
27
27
|
opts = defaults.merge(opts)
|
28
28
|
|
29
|
-
@rme = Reportme::ReportFactory.create
|
29
|
+
@rme = Reportme::ReportFactory.create do
|
30
30
|
|
31
|
+
since opts[:since]
|
31
32
|
connection :adapter => "mysql", :database => "report_me_test", :username => "root", :password => "root", :host => "localhost", :port => 3306
|
32
33
|
|
33
34
|
report :visits do
|
@@ -176,8 +177,8 @@ class ReportmeTest < Test::Unit::TestCase
|
|
176
177
|
periods = {}
|
177
178
|
Reportme::ReportFactory.periods('2009-06-01'.to_date).each{|p| periods[p[:name]] = p}
|
178
179
|
|
179
|
-
assert_equal '2009-06-01 00:00:00'.to_datetime, periods[:today][:von]
|
180
|
-
assert_equal '2009-06-01 23:59:59'.to_datetime, periods[:today][:bis]
|
180
|
+
# assert_equal '2009-06-01 00:00:00'.to_datetime, periods[:today][:von]
|
181
|
+
# assert_equal '2009-06-01 23:59:59'.to_datetime, periods[:today][:bis]
|
181
182
|
|
182
183
|
assert_equal '2009-05-31 00:00:00'.to_datetime, periods[:day][:von]
|
183
184
|
assert_equal '2009-05-31 23:59:59'.to_datetime, periods[:day][:bis]
|
@@ -202,8 +203,8 @@ class ReportmeTest < Test::Unit::TestCase
|
|
202
203
|
periods.clear
|
203
204
|
Reportme::ReportFactory.periods('2009-06-24'.to_date).each{|p| periods[p[:name]] = p}
|
204
205
|
|
205
|
-
assert_equal '2009-06-24 00:00:00'.to_datetime, periods[:today][:von]
|
206
|
-
assert_equal '2009-06-24 23:59:59'.to_datetime, periods[:today][:bis]
|
206
|
+
# assert_equal '2009-06-24 00:00:00'.to_datetime, periods[:today][:von]
|
207
|
+
# assert_equal '2009-06-24 23:59:59'.to_datetime, periods[:today][:bis]
|
207
208
|
|
208
209
|
assert_equal '2009-06-23 00:00:00'.to_datetime, periods[:day][:von]
|
209
210
|
assert_equal '2009-06-23 23:59:59'.to_datetime, periods[:day][:bis]
|
@@ -227,8 +228,8 @@ class ReportmeTest < Test::Unit::TestCase
|
|
227
228
|
periods.clear
|
228
229
|
Reportme::ReportFactory.periods('2009-06-30'.to_date).each{|p| periods[p[:name]] = p}
|
229
230
|
|
230
|
-
assert_equal '2009-06-30 00:00:00'.to_datetime, periods[:today][:von]
|
231
|
-
assert_equal '2009-06-30 23:59:59'.to_datetime, periods[:today][:bis]
|
231
|
+
# assert_equal '2009-06-30 00:00:00'.to_datetime, periods[:today][:von]
|
232
|
+
# assert_equal '2009-06-30 23:59:59'.to_datetime, periods[:today][:bis]
|
232
233
|
|
233
234
|
assert_equal '2009-06-29 00:00:00'.to_datetime, periods[:day][:von]
|
234
235
|
assert_equal '2009-06-29 23:59:59'.to_datetime, periods[:day][:bis]
|
@@ -252,8 +253,8 @@ class ReportmeTest < Test::Unit::TestCase
|
|
252
253
|
periods.clear
|
253
254
|
Reportme::ReportFactory.periods('2009-05-01'.to_date).each{|p| periods[p[:name]] = p}
|
254
255
|
|
255
|
-
assert_equal '2009-05-01 00:00:00'.to_datetime, periods[:today][:von]
|
256
|
-
assert_equal '2009-05-01 23:59:59'.to_datetime, periods[:today][:bis]
|
256
|
+
# assert_equal '2009-05-01 00:00:00'.to_datetime, periods[:today][:von]
|
257
|
+
# assert_equal '2009-05-01 23:59:59'.to_datetime, periods[:today][:bis]
|
257
258
|
|
258
259
|
assert_equal '2009-04-30 00:00:00'.to_datetime, periods[:day][:von]
|
259
260
|
assert_equal '2009-04-30 23:59:59'.to_datetime, periods[:day][:bis]
|
@@ -277,8 +278,8 @@ class ReportmeTest < Test::Unit::TestCase
|
|
277
278
|
periods.clear
|
278
279
|
Reportme::ReportFactory.periods('2009-05-15'.to_date).each{|p| periods[p[:name]] = p}
|
279
280
|
|
280
|
-
assert_equal '2009-05-15 00:00:00'.to_datetime, periods[:today][:von]
|
281
|
-
assert_equal '2009-05-15 23:59:59'.to_datetime, periods[:today][:bis]
|
281
|
+
# assert_equal '2009-05-15 00:00:00'.to_datetime, periods[:today][:von]
|
282
|
+
# assert_equal '2009-05-15 23:59:59'.to_datetime, periods[:today][:bis]
|
282
283
|
|
283
284
|
assert_equal '2009-05-14 00:00:00'.to_datetime, periods[:day][:von]
|
284
285
|
assert_equal '2009-05-14 23:59:59'.to_datetime, periods[:day][:bis]
|
@@ -302,8 +303,8 @@ class ReportmeTest < Test::Unit::TestCase
|
|
302
303
|
periods.clear
|
303
304
|
Reportme::ReportFactory.periods('2009-05-31'.to_date).each{|p| periods[p[:name]] = p}
|
304
305
|
|
305
|
-
assert_equal '2009-05-31 00:00:00'.to_datetime, periods[:today][:von]
|
306
|
-
assert_equal '2009-05-31 23:59:59'.to_datetime, periods[:today][:bis]
|
306
|
+
# assert_equal '2009-05-31 00:00:00'.to_datetime, periods[:today][:von]
|
307
|
+
# assert_equal '2009-05-31 23:59:59'.to_datetime, periods[:today][:bis]
|
307
308
|
|
308
309
|
assert_equal '2009-05-30 00:00:00'.to_datetime, periods[:day][:von]
|
309
310
|
assert_equal '2009-05-30 23:59:59'.to_datetime, periods[:day][:bis]
|
@@ -319,7 +320,17 @@ class ReportmeTest < Test::Unit::TestCase
|
|
319
320
|
|
320
321
|
assert_equal '2009-04-01 00:00:00'.to_datetime, periods[:calendar_month][:von]
|
321
322
|
assert_equal '2009-04-30 23:59:59'.to_datetime, periods[:calendar_month][:bis]
|
323
|
+
|
324
|
+
##
|
325
|
+
# today
|
326
|
+
##
|
322
327
|
|
328
|
+
periods.clear
|
329
|
+
today = Date.today
|
330
|
+
Reportme::ReportFactory.periods(today).each{|p| periods[p[:name]] = p}
|
331
|
+
|
332
|
+
assert_equal "#{today.strftime('%Y-%m-%d')} 00:00:00".to_datetime, periods[:today][:von]
|
333
|
+
assert_equal "#{today.strftime('%Y-%m-%d')} 23:59:59".to_datetime, periods[:today][:bis]
|
323
334
|
|
324
335
|
end
|
325
336
|
|
@@ -411,4 +422,16 @@ class ReportmeTest < Test::Unit::TestCase
|
|
411
422
|
end
|
412
423
|
end
|
413
424
|
end
|
425
|
+
|
426
|
+
should "fail on multiple since calls" do
|
427
|
+
|
428
|
+
rme = create_visit_report_factory
|
429
|
+
# 'since' will be implicitly called by ower testing factory method above
|
430
|
+
# any further call should fails
|
431
|
+
|
432
|
+
assert_raise RuntimeError do
|
433
|
+
rme.since 20.days.ago
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
414
437
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jzimmek-reportme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Zimmek
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-27 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|