lib/dry/schema/path.rb in dry-schema-0.2.0 vs lib/dry/schema/path.rb in dry-schema-0.3.0

- old
+ new

@@ -1,13 +1,17 @@ +# frozen_string_literal: true + require 'dry/schema/constants' module Dry module Schema # Path represents a list of keys in a hash # # @api private class Path + include Enumerable + # !@attribute [r] keys # @return [Array<Symbol>] attr_reader :keys # Coerce a spec into a path object @@ -45,11 +49,26 @@ def initialize(keys) @keys = keys end # @api private - def ==(other) - keys == Path[other].keys + def each(&block) + keys.each(&block) + end + + # @api private + def index(key) + keys.index(key) + end + + # @api private + def include?(other) + !find { |key| (idx = other.index(key)) && keys[idx].equal?(key) }.nil? + end + + # @api private + def <=>(other) + keys.count <=> other.count end end end end