Introduction
Introduction Statistics Contact Development Disclaimer Help
reportable.rb - reportable - Fork of reportable required by WarVox, from hdm/re…
git clone git://jay.scot/reportable
Log
Files
Refs
README
---
reportable.rb (3617B)
---
1
2 require 'saulabs/reportable/report'
3 require 'saulabs/reportable/cumulated_report'
4 require 'saulabs/reportable/railtie'
5
6 module Saulabs
7
8 module Reportable
9
10 # The adapter connects Reportable and Rails.
11 #
12 module RailsAdapter
13
14 # Extends the {Saulabs::Reportable::ClassMethods#reportable} metho…
15 #
16 def self.included(base)
17 base.extend ClassMethods
18 end
19
20 module ClassMethods
21
22 # Generates a report on a model. That report can then be execute…
23 #
24 # @param [String] name
25 # the name of the report, also defines the name of the generat…
26 # @param [Hash] options
27 # the options to generate the reports with
28 #
29 # @option options [Symbol] :date_column (created_at)
30 # the name of the date column over that the records are aggreg…
31 # @option options [String, Symbol] :value_column (:id)
32 # the name of the column that holds the values to aggregate wh…
33 # @option options [Symbol] :aggregation (:count)
34 # the aggregation to use (one of +:count+, +:sum+, +:minimum+,…
35 # @option options [Symbol] :grouping (:day)
36 # the period records are grouped in (+:hour+, +:day+, +:week+,…
37 # @option options [Fixnum] :limit (100)
38 # the number of reporting periods to get (see +:grouping+)
39 # @option options [Hash] :conditions ({})
40 # conditions like in +ActiveRecord::Base#find+; only records t…
41 # @option options [Hash] :include ({})
42 # include like in +ActiveRecord::Base#find+; names association…
43 # @option options [Boolean] :live_data (false)
44 # specifies whether data for the current reporting period is t…
45 # @option options [DateTime, Boolean] :end_date (false)
46 # when specified, the report will only include data for the +:…
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_co…
53 # reportable :total_users, :cumulate => true
54 # reportable :rake, :aggregation => :sum, :value_c…
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…
66 report.run(args.first || {})
67 end
68 end
69 end
70
71 end
72
73 end
74
75 end
76
77 end
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.