Module: Simple::SQL::Helpers

Extended by:
Helpers
Included in:
Helpers
Defined in:
lib/simple/sql/helpers.rb,
lib/simple/sql/helpers.rb,
lib/simple/sql/helpers/immutable.rb

Defined Under Namespace

Modules: Decoder, Encoder, RowConverter

Constant Summary collapse

Immutable =

for backwards compatibility

::Simple::Immutable

Instance Method Summary collapse

Instance Method Details

#by_key(ary, key) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/simple/sql/helpers.rb', line 24

def by_key(ary, key)
  hsh = {}
  ary.each do |entity|
    group = entity.fetch(key)
    hsh[group] = entity
  end
  hsh
end

#pluck(ary, key) ⇒ Object



20
21
22
# File 'lib/simple/sql/helpers.rb', line 20

def pluck(ary, key)
  ary.map { |rec| rec.fetch(key) }
end

#stable_group_by_key(ary, key) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/simple/sql/helpers.rb', line 11

def stable_group_by_key(ary, key)
  hsh = Hash.new { |h, k| h[k] = [] }
  ary.each do |entity|
    group = entity.fetch(key)
    hsh[group] << entity
  end
  hsh
end