class ConfigMapper::Mapper
Something that accepts configuration.
Public Instance Methods
configure_with(data)
click to toggle source
Map configuration data onto the target.
@return [Hash] exceptions encountered
# File lib/config_mapper/mapper.rb, line 11 def configure_with(data) errors = {} if data.respond_to?(:each_pair) data.each_pair do |key, value| configure_attribute(key, value, errors) end else data.each_with_index do |value, index| configure_attribute(index, value, errors) end end errors end
Private Instance Methods
configure_attribute(key, value, errors)
click to toggle source
Set a single attribute.
# File lib/config_mapper/mapper.rb, line 29 def configure_attribute(key, value, errors) attribute_path = path(key) if can_set?(key) set(key, value) else nested_errors = ConfigMapper.configure_with(value, get(key)) nested_errors.each do |nested_path, error| errors["#{attribute_path}#{nested_path}"] = error end end rescue NoMethodError, ArgumentError => e errors[attribute_path] = e end