Introduction
Introduction Statistics Contact Development Disclaimer Help
don't include Saulabs::Reportable into ActiveRecord but use additional RailsAda…
Log
Files
Refs
README
---
commit 835833151951f642554014e677bbfb79907a8e79
parent 6635bd5d1cb277aad7320a902e4450349ff07fe3
Author: Marco Otte-Witte <[email protected]>
Date: Mon, 28 Jun 2010 10:44:46 +0200
don't include Saulabs::Reportable into ActiveRecord but use additional RailsAda…
Diffstat:
M lib/saulabs/reportable.rb | 108 ++++++++++++++++-------------…
M rails/init.rb | 2 +-
2 files changed, 58 insertions(+), 52 deletions(-)
---
diff --git a/lib/saulabs/reportable.rb b/lib/saulabs/reportable.rb
@@ -5,63 +5,69 @@ module Saulabs
module Reportable
- IS_RAILS3 = defined?(Rails) && Rails::VERSION::MAJOR >= 3
-
- require 'saulabs/reportable/railtie' if IS_RAILS3
-
- # Extends the {Saulabs::Reportable::ClassMethods#reportable} method into +…
+ # The adapter connects Reportable and Rails.
#
- def self.included(base)
- base.extend ClassMethods
- end
+ module RailsAdapter
- module ClassMethods
+ IS_RAILS3 = defined?(Rails) && Rails::VERSION::MAJOR >= 3
- # Generates a report on a model. That report can then be executed via th…
- #
- # @param [String] name
- # the name of the report, also defines the name of the generated repor…
- # @param [Hash] options
- # the options to generate the reports with
- #
- # @option options [Symbol] :date_column (created_at)
- # the name of the date column over that the records are aggregated
- # @option options [String, Symbol] :value_column (:id)
- # the name of the column that holds the values to aggregate when using…
- # @option options [Symbol] :aggregation (:count)
- # the aggregation to use (one of +:count+, +:sum+, +:minimum+, +:maxim…
- # @option options [Symbol] :grouping (:day)
- # the period records are grouped in (+:hour+, +:day+, +:week+, +:month…
- # @option options [Fixnum] :limit (100)
- # the number of reporting periods to get (see +:grouping+)
- # @option options [Hash] :conditions ({})
- # conditions like in +ActiveRecord::Base#find+; only records that matc…
- # @option options [Boolean] :live_data (false)
- # specifies whether data for the current reporting period is to be rea…
- # @option options [DateTime, Boolean] :end_date (false)
- # when specified, the report will only include data for the +:limit+ r…
- #
- # @example Declaring reports on a model
+ require 'saulabs/reportable/railtie' if IS_RAILS3
+
+ # Extends the {Saulabs::Reportable::ClassMethods#reportable} method into…
#
- # class User < ActiveRecord::Base
- # reportable :registrations, :aggregation => :count
- # reportable :activations, :aggregation => :count, :date_column => …
- # reportable :total_users, :cumulate => true
- # reportable :rake, :aggregation => :sum, :value_column =>…
- # end
- def reportable(name, options = {})
- (class << self; self; end).instance_eval do
- report_klass = if options.delete(:cumulate)
- Saulabs::Reportable::CumulatedReport
- else
- Saulabs::Reportable::Report
- end
- define_method("#{name.to_s}_report".to_sym) do |*args|
- report = report_klass.new(self, name, options)
- raise ArgumentError.new unless args.empty? || (args.length == 1 &&…
- report.run(args.first || {})
+ def self.included(base)
+ base.extend ClassMethods
+ end
+
+ module ClassMethods
+
+ # Generates a report on a model. That report can then be executed via …
+ #
+ # @param [String] name
+ # the name of the report, also defines the name of the generated rep…
+ # @param [Hash] options
+ # the options to generate the reports with
+ #
+ # @option options [Symbol] :date_column (created_at)
+ # the name of the date column over that the records are aggregated
+ # @option options [String, Symbol] :value_column (:id)
+ # the name of the column that holds the values to aggregate when usi…
+ # @option options [Symbol] :aggregation (:count)
+ # the aggregation to use (one of +:count+, +:sum+, +:minimum+, +:max…
+ # @option options [Symbol] :grouping (:day)
+ # the period records are grouped in (+:hour+, +:day+, +:week+, +:mon…
+ # @option options [Fixnum] :limit (100)
+ # the number of reporting periods to get (see +:grouping+)
+ # @option options [Hash] :conditions ({})
+ # conditions like in +ActiveRecord::Base#find+; only records that ma…
+ # @option options [Boolean] :live_data (false)
+ # specifies whether data for the current reporting period is to be r…
+ # @option options [DateTime, Boolean] :end_date (false)
+ # when specified, the report will only include data for the +:limit+…
+ #
+ # @example Declaring reports on a model
+ #
+ # class User < ActiveRecord::Base
+ # reportable :registrations, :aggregation => :count
+ # reportable :activations, :aggregation => :count, :date_column =…
+ # reportable :total_users, :cumulate => true
+ # reportable :rake, :aggregation => :sum, :value_column …
+ # end
+ def reportable(name, options = {})
+ (class << self; self; end).instance_eval do
+ report_klass = if options.delete(:cumulate)
+ Saulabs::Reportable::CumulatedReport
+ else
+ Saulabs::Reportable::Report
+ end
+ define_method("#{name.to_s}_report".to_sym) do |*args|
+ report = report_klass.new(self, name, options)
+ raise ArgumentError.new unless args.empty? || (args.length == 1 …
+ report.run(args.first || {})
+ end
end
end
+
end
end
diff --git a/rails/init.rb b/rails/init.rb
@@ -3,7 +3,7 @@ require 'saulabs/reportable'
require 'saulabs/reportable/report_tag_helper'
ActiveRecord::Base.class_eval do
- include Saulabs::Reportable
+ include Saulabs::Reportable::RailsAdapter
end
ActionView::Base.class_eval do
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.