Class: EacConfig::PathsHash::Node
- Inherits:
-
Object
- Object
- EacConfig::PathsHash::Node
- Defined in:
- lib/eac_config/paths_hash/node.rb
Constant Summary collapse
- PATH_SEARCH_UNENDED_ERROR_MESSAGE =
'Path search is not a Node and is not ended'
Instance Method Summary collapse
- #entry?(path_search) ⇒ Boolean
- #fetch(path_search) ⇒ Object
-
#initialize(source_hash) ⇒ Node
constructor
A new instance of Node.
- #read_entry(path_search) ⇒ Object
- #to_h ⇒ Object
- #write_entry(path_search, value) ⇒ Object
Constructor Details
Instance Method Details
#entry?(path_search) ⇒ Boolean
13 14 15 16 17 18 19 20 |
# File 'lib/eac_config/paths_hash/node.rb', line 13 def entry?(path_search) return false unless data.key?(path_search.cursor) return true if path_search.ended? return data.fetch(path_search.cursor).entry?(path_search.succeeding) if data.fetch(path_search.cursor).is_a?(Node) false # Paths continue and there is not available nodes end |
#fetch(path_search) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/eac_config/paths_hash/node.rb', line 22 def fetch(path_search) if data.key?(path_search.cursor) node = data.fetch(path_search.cursor) return (node.is_a?(Node) ? node.to_h : node) if path_search.ended? return nil if node.blank? return node.fetch(path_search.succeeding) if node.is_a?(Node) end path_search.raise_error(PATH_SEARCH_UNENDED_ERROR_MESSAGE) end |
#read_entry(path_search) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/eac_config/paths_hash/node.rb', line 37 def read_entry(path_search) node = data[path_search.cursor] return (node.is_a?(Node) ? node.to_h : node) if path_search.ended? return nil if node.blank? return node.read_entry(path_search.succeeding) if node.is_a?(Node) path_search.raise_error(PATH_SEARCH_UNENDED_ERROR_MESSAGE) end |
#to_h ⇒ Object
33 34 35 |
# File 'lib/eac_config/paths_hash/node.rb', line 33 def to_h data.transform_values { |v| v.is_a?(Node) ? v.to_h : v } end |
#write_entry(path_search, value) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/eac_config/paths_hash/node.rb', line 46 def write_entry(path_search, value) if path_search.ended? data[path_search.cursor] = value.is_a?(Hash) ? self.class.new(value) : value else assert_data_node(path_search.cursor).write_entry(path_search.succeeding, value) end end |