Module: Hashed
- Defined in:
- lib/hashed.rb,
lib/hashed/version.rb
Constant Summary collapse
- VERSION =
"0.0.5"
Instance Method Summary collapse
Instance Method Details
#hashed(opts = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/hashed.rb', line 5 def hashed(opts = {}) result = {} opts = { by: opts } if opts.is_a? Symbol = { by: (primary_key.respond_to?(:to_sym) ? primary_key.to_sym : primary_key.to_s), only: false } .merge! opts dataset = [:only] ? select([[:by], [:only]]) : self dataset.all.each do |row| result[row.send([:by])] = ([:only] ? row.send([:only]) : row) end result end |