class Configurations::Maps::Types

Attributes

map[R]

Public Class Methods

new(reader = Readers::Tolerant.new) click to toggle source
# File lib/configurations/maps/types.rb, line 17
def initialize(reader = Readers::Tolerant.new)
  @map = {}
  @reader = reader
end

Public Instance Methods

add(type, properties) click to toggle source
# File lib/configurations/maps/types.rb, line 22
def add(type, properties)
  properties.each do |property|
    add_entry(property, type, @map)
  end
end
add_entry(property, type, subtree) click to toggle source
# File lib/configurations/maps/types.rb, line 39
def add_entry(property, type, subtree)
  if property.is_a?(Hash)
    property.each do |key, val|
      subtree[key] = add_entry(val, type, subtree.fetch(key, {}))
    end
  elsif property.is_a?(Array)
    property.each do |val|
      add_entry(val, type, subtree)
    end
  else
    subtree[property] = Entry.new(type)
  end

  subtree
end
test!(path, value) click to toggle source
# File lib/configurations/maps/types.rb, line 28
def test!(path, value)
  entry = @reader.read(@map, path)
  return unless entry

  fail(
    ConfigurationError,
    "#{path.print} must be configured with #{entry.type} (got #{value})",
    caller
  ) unless entry.valid?(value)
end