Sha256: 422e4b992ab905381efe355f53570454492ec6068bd718edda2108966c756967
Contents?: true
Size: 854 Bytes
Versions: 2
Compression:
Stored size: 854 Bytes
Contents
module ConfigMapper # Something that accepts configuration. # class Mapper # Map configuration data onto the target. # # @return [Hash] exceptions encountered # def configure_with(data) errors = {} data.each do |key, value| configure_attribute(key, value, errors) end errors end private # Set a single attribute. # def configure_attribute(key, value, errors) attribute_path = path(key) if value.is_a?(Hash) && !get(key).nil? nested_errors = ConfigMapper.configure_with(value, get(key)) nested_errors.each do |nested_path, error| errors["#{attribute_path}#{nested_path}"] = error end else set(key, value) end rescue NoMethodError, ArgumentError => e errors[attribute_path] = e end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
config_mapper-1.2.0 | lib/config_mapper/mapper.rb |
config_mapper-1.1.1 | lib/config_mapper/mapper.rb |