class ParamsReady::Helpers::KeyMap::Mapping::Path
Attributes
names[R]
path[R]
Public Class Methods
dig(name, hash, path)
click to toggle source
# File lib/params_ready/helpers/key_map.rb, line 29 def self.dig(name, hash, path) result = path.reduce(hash) do |current, name| next unless Extensions::Hash.acts_as_hash?(current) Extensions::Hash.indifferent_access current, name, nil end return Extensions::Undefined unless Extensions::Hash.acts_as_hash?(result) Extensions::Hash.indifferent_access result, name, Extensions::Undefined end
new(path, names = [])
click to toggle source
# File lib/params_ready/helpers/key_map.rb, line 12 def initialize(path, names = []) @path = path.map(&:to_sym).freeze @names = names end
store(name, value, hash, path)
click to toggle source
# File lib/params_ready/helpers/key_map.rb, line 45 def self.store(name, value, hash, path) return if value == Extensions::Undefined result = path.reduce(hash) do |current, name| current[name] ||= {} current[name] end result[name] = value result end
Public Instance Methods
==(other)
click to toggle source
# File lib/params_ready/helpers/key_map.rb, line 62 def ==(other) raise ParamsReadyError, "Can't compare path with #{other.class.name}" unless other.is_a? Path path == other.path && names == other.names end
=~(other)
click to toggle source
# File lib/params_ready/helpers/key_map.rb, line 57 def =~(other) raise ParamsReadyError, "Can't match path with #{other.class.name}" unless other.is_a? Path path == other.path end
add_name(name)
click to toggle source
# File lib/params_ready/helpers/key_map.rb, line 21 def add_name(name) @names << name end
add_names(names)
click to toggle source
# File lib/params_ready/helpers/key_map.rb, line 17 def add_names(names) names.each{ |name| add_name(name) } end
dig(name, hash)
click to toggle source
# File lib/params_ready/helpers/key_map.rb, line 25 def dig(name, hash) self.class.dig(name, hash, @path) end
store(name, value, hash)
click to toggle source
# File lib/params_ready/helpers/key_map.rb, line 41 def store(name, value, hash) self.class.store(name, value, hash, @path) end