Module: Dry::Validation::Rust::Path Private
- Defined in:
- lib/dry/validation/rust/path.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Normalizes the path forms accepted by dry-validation's public rule API.
Constant Summary collapse
- Undefined =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Object.new.freeze
Class Method Summary collapse
- .expand(spec) ⇒ Object private
- .fetch(data, path, undefined = Undefined) ⇒ Object private
- .key?(data, path) ⇒ Boolean private
- .parse(spec) ⇒ Object private
- .prefix?(candidate, prefix) ⇒ Boolean private
Class Method Details
.expand(spec) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dry/validation/rust/path.rb', line 25 def (spec) return [parse(spec)] unless spec.is_a?(Hash) spec.flat_map do |key, value| if value.is_a?(Array) value.map { |child| [key, *parse(child)] } else [[key, *parse(value)]] end end end |
.fetch(data, path, undefined = Undefined) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/dry/validation/rust/path.rb', line 37 def fetch(data, path, undefined = Undefined) current = data parse(path).each do |key| if current.is_a?(Array) && key.is_a?(Integer) return undefined unless key >= 0 && key < current.length current = current[key] elsif current.respond_to?(:key?) && current.key?(key) current = current[key] else return undefined end end current end |
.key?(data, path) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 |
# File 'lib/dry/validation/rust/path.rb', line 53 def key?(data, path) !fetch(data, path).equal?(Undefined) end |
.parse(spec) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dry/validation/rust/path.rb', line 11 def parse(spec) case spec when nil then [] when Symbol then [spec] when String then spec.split('.').map!(&:to_sym) when Array then spec.dup when Hash key, value = spec.first [key, *parse(value)] else raise ArgumentError, '+spec+ must be a Symbol, String, Array, or Hash' end end |
.prefix?(candidate, prefix) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 58 59 |
# File 'lib/dry/validation/rust/path.rb', line 57 def prefix?(candidate, prefix) candidate[0, prefix.length] == prefix end |