Module: LightMapper

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

Defined Under Namespace

Modules: Helper

Constant Summary collapse

BaseError =
Class.new(StandardError)
InvalidKey =
Class.new(BaseError)
KeyMissing =
Class.new(BaseError)
InvalidStructure =
Class.new(BaseError)
AlreadyAssignedValue =
Class.new(BaseError)
VERSION =
'1.0.5'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

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



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/light_mapper.rb', line 113

def self.mapping(hash, mappings, opts = {})
  strict, any_keys, keys = opts.values_at(:strict, :any_keys, :keys)

  mappings.each_with_object({}) do |(k, v), h|
    next Helper.push(h, v, k.call(hash), keys: keys) if k.is_a?(Proc)

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

Instance Method Details

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



109
110
111
# File 'lib/light_mapper.rb', line 109

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