Module: ConfigMapper

Defined in:
lib/config_mapper.rb,
lib/config_mapper/mapper.rb,
lib/config_mapper/version.rb,
lib/config_mapper/config_dict.rb,
lib/config_mapper/dict_mapper.rb,
lib/config_mapper/config_struct.rb,
lib/config_mapper/object_mapper.rb

Overview

Supports marshalling of plain-old data (e.g. loaded from YAML files) onto strongly-typed objects.

Defined Under Namespace

Classes: ConfigDict, ConfigStruct, DictMapper, Mapper, ObjectMapper

Constant Summary collapse

VERSION =
"1.2.0".freeze

Class Method Summary collapse

Class Method Details

.configure_with(data, target) ⇒ Hash Also known as: set

Set attributes of a target object based on configuration data.

For simple, scalar values, set the attribute by calling the named writer-method on the target object.

For Hash values, set attributes of the named sub-component.

Parameters:

  • data

    configuration data

  • target (Object, Hash)

    the object to configure

Returns:

  • (Hash)

    exceptions encountered



24
25
26
# File 'lib/config_mapper.rb', line 24

def configure_with(data, target)
  mapper_for(target).configure_with(data)
end

.mapper_for(target) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/config_mapper.rb', line 30

def mapper_for(target)
  if target.is_a?(Hash) || target.is_a?(ConfigMapper::ConfigDict)
    DictMapper.new(target)
  else
    ObjectMapper.new(target)
  end
end