Module: DevSuite::Utils::Data::PathAccess::DataTraverser
- Extended by:
- DataTraverser
- Included in:
- DataTraverser
- Defined in:
- lib/dev_suite/utils/data/path_access/data_traverser.rb
Instance Method Summary collapse
-
#assign(data, keys, value) ⇒ Object
Traverse nested data for setting a value.
-
#fetch(data, keys) ⇒ Object
Traverse nested data for retrieving a value.
-
#remove(data, keys) ⇒ Object
Traverse nested data for deleting a value.
Instance Method Details
#assign(data, keys, value) ⇒ Object
Traverse nested data for setting a value
18 19 20 21 22 |
# File 'lib/dev_suite/utils/data/path_access/data_traverser.rb', line 18 def assign(data, keys, value) last_key = keys.pop target = keys.reduce(data) { |current, key| traverse_or_create(current, key) } set_final_value(target, last_key, value) end |
#fetch(data, keys) ⇒ Object
Traverse nested data for retrieving a value
13 14 15 |
# File 'lib/dev_suite/utils/data/path_access/data_traverser.rb', line 13 def fetch(data, keys) keys.reduce(data) { |current, key| traverse_data(current, key) } end |
#remove(data, keys) ⇒ Object
Traverse nested data for deleting a value
25 26 27 28 29 |
# File 'lib/dev_suite/utils/data/path_access/data_traverser.rb', line 25 def remove(data, keys) last_key = keys.pop target = keys.reduce(data) { |current, key| traverse_data(current, key) } delete_final_value(target, last_key) end |