reportable 1.1.0 → 1.1.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/HISTORY.md CHANGED
@@ -1,3 +1,13 @@
1
+ v1.1.2
2
+ ------
3
+
4
+ * pushed a faulty version to Rubygems - need to use a new version number for the fixed version
5
+
6
+ v1.1.1
7
+ ------
8
+
9
+ * not including the whole Saulabs::Reportable namespace into ActiveRecord anymore.
10
+
1
11
  v1.1.0
2
12
  ------
3
13
 
@@ -1,4 +1,4 @@
1
- if Saulabs::Reportable::IS_RAILS3
1
+ if Saulabs::Reportable::RailsAdapter::IS_RAILS3
2
2
 
3
3
  class ReportableJqueryFlotAssetsGenerator < Rails::Generators::Base
4
4
 
@@ -1,4 +1,4 @@
1
- if Saulabs::Reportable::IS_RAILS3
1
+ if Saulabs::Reportable::RailsAdapter::IS_RAILS3
2
2
 
3
3
  class ReportableMigrationGenerator < Rails::Generators::Base
4
4
 
@@ -1,4 +1,4 @@
1
- if Saulabs::Reportable::IS_RAILS3
1
+ if Saulabs::Reportable::RailsAdapter::IS_RAILS3
2
2
 
3
3
  class ReportableRaphaelAssetsGenerator < Rails::Generators::Base
4
4
 
@@ -5,63 +5,69 @@ module Saulabs
5
5
 
6
6
  module Reportable
7
7
 
8
- IS_RAILS3 = defined?(Rails) && Rails::VERSION::MAJOR >= 3
9
-
10
- require 'saulabs/reportable/railtie' if IS_RAILS3
11
-
12
- # Extends the {Saulabs::Reportable::ClassMethods#reportable} method into +base+.
8
+ # The adapter connects Reportable and Rails.
13
9
  #
14
- def self.included(base)
15
- base.extend ClassMethods
16
- end
10
+ module RailsAdapter
17
11
 
18
- module ClassMethods
12
+ IS_RAILS3 = defined?(Rails) && Rails::VERSION::MAJOR >= 3
19
13
 
20
- # Generates a report on a model. That report can then be executed via the new method +<name>_report+ (see documentation of {Saulabs::Reportable::Report#run}).
21
- #
22
- # @param [String] name
23
- # the name of the report, also defines the name of the generated report method (+<name>_report+)
24
- # @param [Hash] options
25
- # the options to generate the reports with
26
- #
27
- # @option options [Symbol] :date_column (created_at)
28
- # the name of the date column over that the records are aggregated
29
- # @option options [String, Symbol] :value_column (:id)
30
- # the name of the column that holds the values to aggregate when using a calculation aggregation like +:sum+
31
- # @option options [Symbol] :aggregation (:count)
32
- # the aggregation to use (one of +:count+, +:sum+, +:minimum+, +:maximum+ or +:average+); when using anything other than +:count+, +:value_column+ must also be specified
33
- # @option options [Symbol] :grouping (:day)
34
- # the period records are grouped in (+:hour+, +:day+, +:week+, +:month+); <b>Beware that <tt>reportable</tt> treats weeks as starting on monday!</b>
35
- # @option options [Fixnum] :limit (100)
36
- # the number of reporting periods to get (see +:grouping+)
37
- # @option options [Hash] :conditions ({})
38
- # conditions like in +ActiveRecord::Base#find+; only records that match these conditions are reported;
39
- # @option options [Boolean] :live_data (false)
40
- # specifies whether data for the current reporting period is to be read; <b>if +:live_data+ is +true+, you will experience a performance hit since the request cannot be satisfied from the cache alone</b>
41
- # @option options [DateTime, Boolean] :end_date (false)
42
- # when specified, the report will only include data for the +:limit+ reporting periods until this date.
43
- #
44
- # @example Declaring reports on a model
14
+ require 'saulabs/reportable/railtie' if IS_RAILS3
15
+
16
+ # Extends the {Saulabs::Reportable::ClassMethods#reportable} method into +base+.
45
17
  #
46
- # class User < ActiveRecord::Base
47
- # reportable :registrations, :aggregation => :count
48
- # reportable :activations, :aggregation => :count, :date_column => :activated_at
49
- # reportable :total_users, :cumulate => true
50
- # reportable :rake, :aggregation => :sum, :value_column => :profile_visits
51
- # end
52
- def reportable(name, options = {})
53
- (class << self; self; end).instance_eval do
54
- report_klass = if options.delete(:cumulate)
55
- Saulabs::Reportable::CumulatedReport
56
- else
57
- Saulabs::Reportable::Report
58
- end
59
- define_method("#{name.to_s}_report".to_sym) do |*args|
60
- report = report_klass.new(self, name, options)
61
- raise ArgumentError.new unless args.empty? || (args.length == 1 && args.first.is_a?(Hash))
62
- report.run(args.first || {})
18
+ def self.included(base)
19
+ base.extend ClassMethods
20
+ end
21
+
22
+ module ClassMethods
23
+
24
+ # Generates a report on a model. That report can then be executed via the new method +<name>_report+ (see documentation of {Saulabs::Reportable::Report#run}).
25
+ #
26
+ # @param [String] name
27
+ # the name of the report, also defines the name of the generated report method (+<name>_report+)
28
+ # @param [Hash] options
29
+ # the options to generate the reports with
30
+ #
31
+ # @option options [Symbol] :date_column (created_at)
32
+ # the name of the date column over that the records are aggregated
33
+ # @option options [String, Symbol] :value_column (:id)
34
+ # the name of the column that holds the values to aggregate when using a calculation aggregation like +:sum+
35
+ # @option options [Symbol] :aggregation (:count)
36
+ # the aggregation to use (one of +:count+, +:sum+, +:minimum+, +:maximum+ or +:average+); when using anything other than +:count+, +:value_column+ must also be specified
37
+ # @option options [Symbol] :grouping (:day)
38
+ # the period records are grouped in (+:hour+, +:day+, +:week+, +:month+); <b>Beware that <tt>reportable</tt> treats weeks as starting on monday!</b>
39
+ # @option options [Fixnum] :limit (100)
40
+ # the number of reporting periods to get (see +:grouping+)
41
+ # @option options [Hash] :conditions ({})
42
+ # conditions like in +ActiveRecord::Base#find+; only records that match these conditions are reported;
43
+ # @option options [Boolean] :live_data (false)
44
+ # specifies whether data for the current reporting period is to be read; <b>if +:live_data+ is +true+, you will experience a performance hit since the request cannot be satisfied from the cache alone</b>
45
+ # @option options [DateTime, Boolean] :end_date (false)
46
+ # when specified, the report will only include data for the +:limit+ reporting periods until this date.
47
+ #
48
+ # @example Declaring reports on a model
49
+ #
50
+ # class User < ActiveRecord::Base
51
+ # reportable :registrations, :aggregation => :count
52
+ # reportable :activations, :aggregation => :count, :date_column => :activated_at
53
+ # reportable :total_users, :cumulate => true
54
+ # reportable :rake, :aggregation => :sum, :value_column => :profile_visits
55
+ # end
56
+ def reportable(name, options = {})
57
+ (class << self; self; end).instance_eval do
58
+ report_klass = if options.delete(:cumulate)
59
+ Saulabs::Reportable::CumulatedReport
60
+ else
61
+ Saulabs::Reportable::Report
62
+ end
63
+ define_method("#{name.to_s}_report".to_sym) do |*args|
64
+ report = report_klass.new(self, name, options)
65
+ raise ArgumentError.new unless args.empty? || (args.length == 1 && args.first.is_a?(Hash))
66
+ report.run(args.first || {})
67
+ end
63
68
  end
64
69
  end
70
+
65
71
  end
66
72
 
67
73
  end
@@ -3,7 +3,7 @@ require 'saulabs/reportable'
3
3
  require 'saulabs/reportable/report_tag_helper'
4
4
 
5
5
  ActiveRecord::Base.class_eval do
6
- include Saulabs::Reportable
6
+ include Saulabs::Reportable::RailsAdapter
7
7
  end
8
8
 
9
9
  ActionView::Base.class_eval do
@@ -25,7 +25,7 @@ ActiveRecord::Schema.define(:version => 1) do
25
25
  :grouping,
26
26
  :aggregation,
27
27
  :conditions
28
- ], :name => :name_model_grouping_agregation
28
+ ], :name => 'name_model_grouping_agregation'
29
29
  add_index :reportable_cache, [
30
30
  :model_name,
31
31
  :report_name,
@@ -33,6 +33,6 @@ ActiveRecord::Schema.define(:version => 1) do
33
33
  :aggregation,
34
34
  :conditions,
35
35
  :reporting_period
36
- ], :unique => true, :name => :name_model_grouping_aggregation_period
36
+ ], :unique => true, :name => 'name_model_grouping_aggregation_period'
37
37
 
38
38
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reportable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 0
10
- version: 1.1.0
9
+ - 2
10
+ version: 1.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marco Otte-Witte
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-05-26 00:00:00 +02:00
19
+ date: 2010-06-28 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency