jzimmek-reportme 0.0.5 → 0.0.6

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 CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -25,12 +25,8 @@ module Reportme
25
25
  @periods.include?(period)
26
26
  end
27
27
 
28
- def periods
29
-
30
- end
31
-
32
- def sql(von, bis)
33
- @source.call(von, bis)
28
+ def sql(von, bis, period_name)
29
+ @source.call(von, bis, period_name)
34
30
  end
35
31
 
36
32
  def table_name(period)
@@ -49,11 +49,11 @@ module Reportme
49
49
  end
50
50
 
51
51
  def report_information_table_name_exist?
52
- ActiveRecord::Base.connection.select_value("show tables like '#{report_information_table_name}'") != nil
52
+ select_value("show tables like '#{report_information_table_name}'") != nil
53
53
  end
54
54
 
55
55
  def report_exists?(name, von, bis)
56
- ActiveRecord::Base.connection.select_value("select 1 from #{report_information_table_name} where report = '#{name}' and von = '#{von}' and bis = '#{bis}'") != nil
56
+ select_value("select 1 from #{report_information_table_name} where report = '#{name}' and von = '#{von}' and bis = '#{bis}'") != nil
57
57
  end
58
58
 
59
59
  def reset
@@ -95,42 +95,43 @@ module Reportme
95
95
 
96
96
  @reports.each do |r|
97
97
 
98
- next unless r.wants_period?(period[:name])
98
+ period_name = period[:name]
99
+
100
+ next unless r.wants_period?(period_name)
99
101
 
100
102
  von = period[:von].strftime("%Y-%m-%d 00:00:00")
101
103
  bis = period[:bis].strftime("%Y-%m-%d 23:59:59")
102
104
 
103
- table_name = r.table_name(period[:name])
105
+ table_name = r.table_name(period_name)
104
106
 
105
107
  if debug
106
108
  # drop and create table while in testing mode
107
109
  exec("drop table if exists #{table_name};")
108
110
  end
109
111
 
110
- table_exist = r.table_exist?(period[:name])
111
- sql = r.sql(von, bis)
112
+ table_exist = r.table_exist?(period_name)
113
+ sql = r.sql(von, bis, period_name)
112
114
  report_exist = report_exists?(table_name, von, bis)
113
115
 
114
- puts "report: #{r.name}_#{period[:name]} :: #{report_exist}"
116
+ puts "report: #{r.name}_#{period_name}"
115
117
 
116
118
 
117
119
  unless table_exist
118
120
  exec("create table #{table_name} ENGINE=InnoDB default CHARSET=utf8 as #{sql} limit 0;")
119
121
  end
120
122
 
121
- puts sql
122
123
 
123
- # if !report_exist || period[:name] == :today
124
- # ActiveRecord::Base.transaction do
125
- # exec("insert into #{report_information_table_name} values ('#{table_name}', '#{von}', '#{bis}', now());") unless report_exist
126
- #
127
- # if period[:name] == :today
128
- # exec("truncate #{table_name};")
129
- # end
130
- #
131
- # exec("insert into #{table_name} #{sql};")
132
- # end
133
- # end
124
+ if !report_exist || period_name == :today
125
+ ActiveRecord::Base.transaction do
126
+ exec("insert into #{report_information_table_name} values ('#{table_name}', '#{von}', '#{bis}', now());") unless report_exist
127
+
128
+ if period_name == :today
129
+ exec("truncate #{table_name};")
130
+ end
131
+
132
+ exec("insert into #{table_name} #{sql};")
133
+ end
134
+ end
134
135
 
135
136
 
136
137
  end
@@ -138,10 +139,23 @@ module Reportme
138
139
  end
139
140
 
140
141
  def exec(sql)
142
+ puts "// ------------------------"
143
+ puts "exec: #{sql}"
144
+ puts "------------------------ //"
141
145
  ActiveRecord::Base.connection.execute(sql)
142
146
  end
147
+
148
+ def select_value(sql)
149
+ puts "// ------------------------"
150
+ puts "select_value: #{sql}"
151
+ puts "------------------------ //"
152
+ ActiveRecord::Base.connection.select_value(sql)
153
+ end
143
154
 
144
155
  def report(name, &block)
156
+
157
+ name = name.to_sym
158
+
145
159
  r = Report.new(name)
146
160
  r.instance_eval(&block)
147
161
 
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.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Zimmek