Module: LightMapper

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

Defined Under Namespace

Modules: Helper

Constant Summary collapse

InvalidKey =
Class.new(StandardError)
KeyMissing =
Class.new(StandardError)
VERSION =
'1.0.4'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

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



69
70
71
72
73
74
75
76
77
# File 'lib/light_mapper.rb', line 69

def self.mapping(hash, mappings, opts = {})
  strict, any_keys = opts.values_at(:strict, :any_keys)
  mappings.each_with_object({}) do |(k, v), h|
    next h[v] = k.call(hash) if k.is_a?(Proc)

    key_path = Helper.key_destructor(k)
    h[v] = Helper.value_extractor(hash, key_path.first, key_path[1..-1], key_path, strict, any_keys)
  end
end

Instance Method Details

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



65
66
67
# File 'lib/light_mapper.rb', line 65

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