Module: Torque::PostgreSQL::Relation::Buckets::Initializer

Included in:
Initializer
Defined in:
lib/torque/postgresql/relation/buckets.rb

Instance Method Summary collapse

Instance Method Details

#recordsObject

Hook into the output of records to make sure we group by the buckets



59
60
61
62
63
64
65
66
67
68
# File 'lib/torque/postgresql/relation/buckets.rb', line 59

def records
  return super if buckets_value.blank?

  keys = buckets_keys
  col = buckets_column
  super.group_by do |record|
    val = (record[col] || 0) - 1
    keys[val] if val >= 0 && val < keys.size
  end
end