Sha256: 155e674462a074381d701880f202a92fcd938d4d09d2912ce2b98be7d16880f5

Contents?: true

Size: 996 Bytes

Versions: 1

Compression:

Stored size: 996 Bytes

Contents

require "config_mapper/config_dict"
require "config_mapper/dict_mapper"
require "config_mapper/object_mapper"

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

  class << self

    # 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.
    #
    # @param data configuration data
    # @param [Object, Hash] target the object to configure
    #
    # @return [Hash] exceptions encountered
    #
    def configure_with(data, target)
      mapper_for(target).configure_with(data)
    end

    alias set configure_with

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

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
config_mapper-1.2.0 lib/config_mapper.rb