module Aggrobot

Constants

DEFAULT_GROUP_BY
VERSION

Public Class Methods

block(&block) click to toggle source
# File lib/aggrobot.rb, line 31
def self.block(&block)
  block
end
setup(app) click to toggle source

sets ROUNDING_DIGITS to percent_precision, default is 2

# File lib/aggrobot.rb, line 36
def self.setup(app)
  SQLFunctions.setup(app.config.aggrobot.percent_precision)
end
start(collection = nil, block_arg = nil, block_opts = nil, &block) click to toggle source

when

collection is given, starts aggregation by evaluating block on collection
collection is not given, starts aggregation by evaluating block on full data set
# File lib/aggrobot.rb, line 20
def self.start(collection = nil, block_arg = nil, block_opts = nil, &block)
  block_opts ||= block_arg if block
  block = block_arg if block_arg && block_arg.respond_to?(:call)
  raise 'Block parameter required' unless block
  original_block_context = eval "self", block.binding
  attrs = if block.arity > 0
            block_opts.is_a?(Hash) ? block_opts : {count: collection.count}
          end
  Aggrobot.new(original_block_context, collection).instance_exec(attrs, &block)
end