class Dry::Schema::KeyMap
@api public
Instances of this class are used as the very first step by the schema processors.
to rebuild an input hash using configured coercer function.
KeyMap objects expose an API for introspecting schema keys and the ability
Represents a list of keys defined by the DSL
def self.[](*keys)
- Api: - public
Returns:
-
(KeyMap)
-
def self.[](*keys) new(keys) end
def self.new(*args)
-
(KeyMap)
-
Parameters:
-
args
(Array
) --, Array, Hash Array>
def self.new(*args) fetch_or_store(*args) { super } end
def +(other)
-
(KeyMap)
-
Parameters:
-
other
(KeyMap, Array
) -- Either a key map or an array with key specs
def +(other) self.class.new(keys + other.to_a) end
def coercible(&coercer)
- Api: - public
Returns:
-
(KeyMap)
-
def coercible(&coercer) self.class.new(map { |key| key.coercible(&coercer) }) end
def dump
-
(Array)
-
def dump keys.map(&:dump) end
def each(&block)
- Api: - public
def each(&block) keys.each(&block) end
def initialize(keys)
- Api: - private
def initialize(keys) @keys = keys.map { |key| case key when Hash root, rest = key.flatten Key::Hash[root, members: KeyMap[*rest]] when Array root, rest = key Key::Array[root, member: KeyMap[*rest]] when Key key else Key[key] end } end
def inspect
-
(String)
-
def inspect "#<#{self.class}[#{keys.map(&:dump).map(&:inspect).join(", ")}]>" end
def stringified
- Api: - public
Returns:
-
(KeyMap)
-
def stringified self.class.new(map(&:stringified)) end
def write(source, target = EMPTY_HASH.dup)
- Api: - public
Returns:
-
(Hash)
-
Parameters:
-
target
(Hash
) -- The target hash -
source
(Hash
) -- The source hash
def write(source, target = EMPTY_HASH.dup) each { |key| key.write(source, target) } target end