class Dry::Schema::Path
@api private
Path represents a list of keys in a hash
def self.[](spec)
- Api: - private
def self.[](spec) call(spec) end
def self.call(spec)
- Api: - private
Returns:
-
(Path)
-
Parameters:
-
spec
(Path, Symbol, String, Hash, Array
) --
def self.call(spec) case spec when ::Symbol, ::Array new([*spec]) when ::String new(spec.split(DOT).map(&:to_sym)) when ::Hash new(keys_from_hash(spec)) when self spec else raise ::ArgumentError, "+spec+ must be either a Symbol, Array, Hash or a #{name}" end end
def self.keys_from_hash(hash)
- Api: - private
def self.keys_from_hash(hash) hash.inject([]) { |a, (k, v)| v.is_a?(::Hash) ? a.push(k, *keys_from_hash(v)) : a.push(k, v) } end
def &(other)
- Api: - private
def &(other) self.class.new( keys.take_while.with_index { |key, index| other.keys[index].eql?(key) } ) end
def <=>(other)
- Api: - private
def <=>(other) return keys.length <=> other.keys.length if include?(other) || other.include?(self) first_uncommon_index = (self & other).keys.length keys[first_uncommon_index] <=> other.keys[first_uncommon_index] end
def each(&)
- Api: - private
def each(&) keys.each(&) end
def include?(other)
- Api: - private
def include?(other) keys[0, other.keys.length].eql?(other.keys) end
def initialize(keys)
- Api: - private
def initialize(keys) @keys = keys end
def last
- Api: - private
def last keys.last end
def same_root?(other)
- Api: - private
def same_root?(other) root.equal?(other.root) end
def to_h(value = EMPTY_ARRAY.dup)
- Api: - private
def to_h(value = EMPTY_ARRAY.dup) value = [value] unless value.is_a?(::Array) keys.reverse_each.reduce(value) { |result, key| {key => result} } end