reportable 1.1.0 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +10 -0
- data/generators/reportable_jquery_flot_assets/reportable_jquery_flot_assets_generator.rb +1 -1
- data/generators/reportable_migration/reportable_migration_generator.rb +1 -1
- data/generators/reportable_raphael_assets/reportable_raphael_assets_generator.rb +1 -1
- data/lib/saulabs/reportable.rb +57 -51
- data/rails/init.rb +1 -1
- data/spec/db/schema.rb +2 -2
- metadata +4 -4
data/HISTORY.md
CHANGED
data/lib/saulabs/reportable.rb
CHANGED
@@ -5,63 +5,69 @@ module Saulabs
|
|
5
5
|
|
6
6
|
module Reportable
|
7
7
|
|
8
|
-
|
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
|
-
|
15
|
-
base.extend ClassMethods
|
16
|
-
end
|
10
|
+
module RailsAdapter
|
17
11
|
|
18
|
-
|
12
|
+
IS_RAILS3 = defined?(Rails) && Rails::VERSION::MAJOR >= 3
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
#
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
data/rails/init.rb
CHANGED
data/spec/db/schema.rb
CHANGED
@@ -25,7 +25,7 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
25
25
|
:grouping,
|
26
26
|
:aggregation,
|
27
27
|
:conditions
|
28
|
-
], :name =>
|
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 =>
|
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:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
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-
|
19
|
+
date: 2010-06-28 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|