jzimmek-reportme 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/reportme.rb +1 -0
- data/lib/reportme/mailer.rb +35 -0
- data/lib/reportme/report.rb +8 -1
- data/lib/reportme/report_factory.rb +41 -1
- data/test/reportme_test.rb +24 -0
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/reportme.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Reportme
|
2
|
+
class Mailer < ActionMailer::Base
|
3
|
+
def message (from, recipients, subject, body, attachments=[])
|
4
|
+
from 'jan.zimmek@toptarif.de'
|
5
|
+
recipients 'jan.zimmek@toptarif.de'
|
6
|
+
subject subject
|
7
|
+
body body
|
8
|
+
|
9
|
+
attachments.each do |att|
|
10
|
+
content_type = att[:content_type]
|
11
|
+
|
12
|
+
attachment content_type do |a|
|
13
|
+
a.filename = att[:filename]
|
14
|
+
|
15
|
+
a.body = File.read(att[:filepath]) if att[:filepath]
|
16
|
+
a.body = att[:text] if att[:text]
|
17
|
+
|
18
|
+
a.transfer_encoding = 'quoted-printable' if content_type =~ /^text\//
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# # Include all the pdf files in the PDF subdirectory as attachments.
|
23
|
+
# FileList['PDF/*.pdf'].each do |path|
|
24
|
+
# file = File.basename(path)
|
25
|
+
# mime_type = MIME::Types.of(file).first
|
26
|
+
# content_type = mime_type ? mime_type.content_type : 'application/binary'
|
27
|
+
# attachment (content_type) do |a|
|
28
|
+
# a.body = File.read(path)
|
29
|
+
# a.filename = file
|
30
|
+
# a.transfer_encoding = 'quoted-printable' if content_type =~ /^text\//
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/reportme/report.rb
CHANGED
@@ -3,7 +3,8 @@ module Reportme
|
|
3
3
|
|
4
4
|
attr_reader :name
|
5
5
|
|
6
|
-
def initialize(name)
|
6
|
+
def initialize(report_factory, name)
|
7
|
+
@report_factory = report_factory
|
7
8
|
@name = name
|
8
9
|
@periods = [:today, :day, :week, :calendar_week, :month, :calendar_month]
|
9
10
|
end
|
@@ -36,6 +37,12 @@ module Reportme
|
|
36
37
|
def table_exist?(period)
|
37
38
|
ActiveRecord::Base.connection.select_value("show tables like '#{table_name(period)}'") != nil
|
38
39
|
end
|
40
|
+
|
41
|
+
def select_value(sql); @report_factory.select_value(sql); end
|
42
|
+
def select_values(sql); @report_factory.select_values(sql); end
|
43
|
+
def select_all(sql); @report_factory.select_all(sql); end
|
44
|
+
def select_rows(sql); @report_factory.select_rows(sql); end
|
45
|
+
def columns(table_name); @report_factory.columns(table_name); end
|
39
46
|
|
40
47
|
end
|
41
48
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'reportme/report'
|
2
|
+
require 'reportme/mailer'
|
2
3
|
|
3
4
|
module Reportme
|
4
5
|
class ReportFactory
|
@@ -18,6 +19,7 @@ module Reportme
|
|
18
19
|
@since = since.to_date
|
19
20
|
@subscribtions = {}
|
20
21
|
@report_exists_cache = []
|
22
|
+
@mailserver = nil
|
21
23
|
end
|
22
24
|
|
23
25
|
def connect
|
@@ -28,6 +30,21 @@ module Reportme
|
|
28
30
|
def connection(properties)
|
29
31
|
@properties = properties
|
30
32
|
end
|
33
|
+
|
34
|
+
def smtp(settings)
|
35
|
+
ActionMailer::Base.smtp_settings = settings
|
36
|
+
end
|
37
|
+
|
38
|
+
def mail(from, recipients, subject, body, attachments=[])
|
39
|
+
Mailer.deliver_message(subject, body, subject, body, attachments)
|
40
|
+
end
|
41
|
+
|
42
|
+
def init(&block)
|
43
|
+
|
44
|
+
raise "only one init block allowed" if @init
|
45
|
+
|
46
|
+
@init = block;
|
47
|
+
end
|
31
48
|
|
32
49
|
def self.periods(today = Date.today)
|
33
50
|
|
@@ -176,6 +193,8 @@ module Reportme
|
|
176
193
|
|
177
194
|
def run
|
178
195
|
|
196
|
+
@init.call if @init
|
197
|
+
|
179
198
|
ensure_report_informations_table_exist
|
180
199
|
|
181
200
|
periods_queue = []
|
@@ -268,6 +287,27 @@ module Reportme
|
|
268
287
|
ActiveRecord::Base.connection.select_value(sql)
|
269
288
|
end
|
270
289
|
|
290
|
+
def select_one(sql)
|
291
|
+
puts "// ------------------------"
|
292
|
+
puts "select_one: #{sql}"
|
293
|
+
puts "------------------------ //"
|
294
|
+
ActiveRecord::Base.connection.select_one(sql)
|
295
|
+
end
|
296
|
+
|
297
|
+
def select_all(sql)
|
298
|
+
puts "// ------------------------"
|
299
|
+
puts "select_all: #{sql}"
|
300
|
+
puts "------------------------ //"
|
301
|
+
ActiveRecord::Base.connection.select_all(sql)
|
302
|
+
end
|
303
|
+
|
304
|
+
def select_rows(sql)
|
305
|
+
puts "// ------------------------"
|
306
|
+
puts "select_rows: #{sql}"
|
307
|
+
puts "------------------------ //"
|
308
|
+
ActiveRecord::Base.connection.select_rows(sql)
|
309
|
+
end
|
310
|
+
|
271
311
|
def select_values(sql)
|
272
312
|
puts "// ------------------------"
|
273
313
|
puts "select_values: #{sql}"
|
@@ -308,7 +348,7 @@ module Reportme
|
|
308
348
|
|
309
349
|
name = name.to_sym
|
310
350
|
|
311
|
-
r = Report.new(name)
|
351
|
+
r = Report.new(self, name)
|
312
352
|
r.instance_eval(&block)
|
313
353
|
|
314
354
|
@reports << r
|
data/test/reportme_test.rb
CHANGED
@@ -386,5 +386,29 @@ class ReportmeTest < Test::Unit::TestCase
|
|
386
386
|
|
387
387
|
assert notifed
|
388
388
|
end
|
389
|
+
|
390
|
+
should "call initializer before running reports" do
|
391
|
+
initialized = false
|
392
|
+
|
393
|
+
rme = create_visit_report_factory
|
394
|
+
rme.init do
|
395
|
+
initialized = true
|
396
|
+
end
|
397
|
+
rme.run
|
398
|
+
|
399
|
+
assert initialized
|
400
|
+
|
401
|
+
end
|
402
|
+
|
403
|
+
should "fail when multiple init blocks are defined" do
|
404
|
+
|
405
|
+
rme = create_visit_report_factory
|
406
|
+
rme.init do
|
407
|
+
end
|
389
408
|
|
409
|
+
assert_raise RuntimeError do
|
410
|
+
rme.init do
|
411
|
+
end
|
412
|
+
end
|
413
|
+
end
|
390
414
|
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.
|
4
|
+
version: 0.2.0
|
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-25 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -28,6 +28,7 @@ files:
|
|
28
28
|
- Rakefile
|
29
29
|
- VERSION
|
30
30
|
- lib/reportme.rb
|
31
|
+
- lib/reportme/mailer.rb
|
31
32
|
- lib/reportme/report.rb
|
32
33
|
- lib/reportme/report_factory.rb
|
33
34
|
- test/reportme_test.rb
|