Module: ConfigMapper

Defined in:
lib/config_mapper.rb,
lib/config_mapper/mapper.rb,
lib/config_mapper/factory.rb,
lib/config_mapper/version.rb,
lib/config_mapper/validator.rb,
lib/config_mapper/config_dict.rb,
lib/config_mapper/config_list.rb,
lib/config_mapper/config_struct.rb,
lib/config_mapper/mapping_error.rb,
lib/config_mapper/object_mapper.rb,
lib/config_mapper/collection_mapper.rb

Overview

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

Defined Under Namespace

Modules: Factory, Validator Classes: CollectionMapper, ConfigDict, ConfigList, ConfigStruct, Mapper, MappingError, ObjectMapper, ProcFactory

Constant Summary collapse

VERSION =
"1.8.0"

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



27
28
29
# File 'lib/config_mapper.rb', line 27

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

.mapper_for(target) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/config_mapper.rb', line 33

def mapper_for(target)
  if target.respond_to?(:[]) && target.respond_to?(:each)
    CollectionMapper.new(target)
  else
    ObjectMapper.new(target)
  end
end