Sha256: 97cc706fe6ef8586c7ed7a3aaed6e7e956b46f600f51e7c25c00136c4c3b28cb

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require "config_mapper/collection_mapper"
require "config_mapper/config_dict"
require "config_mapper/config_list"
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.respond_to?(:[]) && target.respond_to?(:each)
        CollectionMapper.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.8.0 lib/config_mapper.rb