class ActiveReporter::Aggregator::Base
Attributes
name[R]
opts[R]
report[R]
Public Class Methods
new(name, report, opts={})
click to toggle source
# File lib/active_reporter/aggregator/base.rb, line 6 def initialize(name, report, opts={}) @name = name @report = report @opts = opts validate_params! end
Public Instance Methods
aggregate(groups)
click to toggle source
# File lib/active_reporter/aggregator/base.rb, line 21 def aggregate(groups) relate(groups).select("#{function} AS #{sql_value_name}") end
default_value()
click to toggle source
# File lib/active_reporter/aggregator/base.rb, line 17 def default_value opts.fetch(:default_value, nil) end
sql_value_name()
click to toggle source
# File lib/active_reporter/aggregator/base.rb, line 13 def sql_value_name "_report_aggregator_#{name}" end
Private Instance Methods
attribute()
click to toggle source
# File lib/active_reporter/aggregator/base.rb, line 45 def attribute opts.fetch(:attribute, name) end
column()
click to toggle source
# File lib/active_reporter/aggregator/base.rb, line 60 def column opts.fetch(:column, attribute) end
enum?()
click to toggle source
# File lib/active_reporter/aggregator/base.rb, line 68 def enum? false # Hash(model&.defined_enums).include?(attribute.to_s) end
expression()
click to toggle source
# File lib/active_reporter/aggregator/base.rb, line 64 def expression opts.fetch(:expression, "#{table_name}.#{column}") end
model()
click to toggle source
# File lib/active_reporter/aggregator/base.rb, line 41 def model opts.fetch(:model, report.report_model) end
relate(groups)
click to toggle source
# File lib/active_reporter/aggregator/base.rb, line 33 def relate(groups) relation.call(groups) end
relation()
click to toggle source
# File lib/active_reporter/aggregator/base.rb, line 37 def relation opts.fetch(:relation, ->(r) { r }) end
table_name()
click to toggle source
# File lib/active_reporter/aggregator/base.rb, line 49 def table_name return @table_name unless @table_name.nil? @table_name = opts[:table_name] @table_name = model.try(:table_name) if @table_name.nil? @table_name = model.to_s.constantize.try(:table_name) rescue nil if @table_name.nil? @table_name = report.table_name if @table_name.nil? @table_name end
validate_params!()
click to toggle source
# File lib/active_reporter/aggregator/base.rb, line 27 def validate_params! if opts.include?(:expression) ActiveSupport::Deprecation.warn("passing an :expression option will be deprecated in version 1.0\n please use :attribute, and, when required, :model or :table_name") end end