Module: ArAggregateByInterval
- Defined in:
- lib/ar_aggregate_by_interval.rb,
lib/ar_aggregate_by_interval/utils.rb,
lib/ar_aggregate_by_interval/version.rb,
lib/ar_aggregate_by_interval/query_result.rb,
lib/ar_aggregate_by_interval/query_runner.rb
Overview
POSTGRES AND MYSQL COMPATIBLE ActiveRecordModel._ examples:
Defined Under Namespace
Modules: Utils Classes: QueryResult, QueryRunner
Constant Summary collapse
- VERSION =
'1.1.0'
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ar_aggregate_by_interval.rb', line 10 def method_missing(method_name, *args) supported_methods_rgx = /\A(count|sum|avg)_(daily|weekly|monthly)\z/ aggregate_function, interval = method_name.to_s.scan(supported_methods_rgx).flatten return super unless aggregate_function && interval hash_args = if args.size == 1 && args.first.is_a?(Hash) args.first elsif args.size > 1 && !args.any?{ |a| a.is_a?(Hash) } Utils.args_to_hash(aggregate_function, interval, *args) else nil end return super unless hash_args QueryRunner.new(self, { aggregate_function: aggregate_function, interval: interval }.merge(hash_args)) end |