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 +1 -1
 - data/lib/reportme/report.rb +2 -6
 - data/lib/reportme/report_factory.rb +33 -19
 - metadata +1 -1
 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0.0. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.0.6
         
     | 
    
        data/lib/reportme/report.rb
    CHANGED
    
    
| 
         @@ -49,11 +49,11 @@ module Reportme 
     | 
|
| 
       49 
49 
     | 
    
         
             
                end
         
     | 
| 
       50 
50 
     | 
    
         | 
| 
       51 
51 
     | 
    
         
             
                def report_information_table_name_exist?
         
     | 
| 
       52 
     | 
    
         
            -
                   
     | 
| 
      
 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 
     | 
    
         
            -
                   
     | 
| 
      
 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 
     | 
    
         
            -
                       
     | 
| 
      
 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( 
     | 
| 
      
 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?( 
     | 
| 
       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}_#{ 
     | 
| 
      
 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 
     | 
    
         
            -
                       
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
                       
     | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
                       
     | 
| 
      
 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 
     | 
    
         |