Module: LightMapper

Defined in:
lib/light_mapper.rb,
lib/light_mapper/version.rb

Constant Summary collapse

VERSION =
'0.0.1'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.mapping(hash, mappings, opts = {}) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/light_mapper.rb', line 8

def self.mapping(hash, mappings, opts = {})
  require_keys = opts[:require_keys] == true

  fetch_method = require_keys ? :fetch : :[]
  {}.tap do |h|
    mappings.each { |k, v| h[v] = hash.public_send(fetch_method, k) }
  end
end

Instance Method Details

#mapping(mappings, opts = {}) ⇒ Object



4
5
6
# File 'lib/light_mapper.rb', line 4

def mapping(mappings, opts = {})
  LightMapper.mapping(clone, mappings, opts)
end