Sha256: d0b499ffe4d8f2c3fffb4ace3054a9aa1ed51752dc3c74f6791a7a3d6d603074
Contents?: true
Size: 927 Bytes
Versions: 13
Compression:
Stored size: 927 Bytes
Contents
module ForestLiana class ValueStatGetter attr_accessor :record def initialize(resource, params) @resource = resource @params = params end def perform return if @params[:aggregate].blank? value = @resource @params[:filters].try(:each) do |filter| operator, filter_value = OperatorValueParser.parse(filter[:value]) value = value.where("#{filter[:field]} #{operator} '#{filter_value}'") end @record = Stat.new(value: count(value)) end private def count(value) uniq = @params[:aggregate].downcase == 'count' if Rails::VERSION::MAJOR == 4 value = value.uniq if uniq value.send(@params[:aggregate].downcase, aggregate_field) else value.send(@params[:aggregate], aggregate_field, distinct: uniq) end end def aggregate_field @params[:aggregate_field] || :id end end end
Version data entries
13 entries across 13 versions & 1 rubygems