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
16 17 18 19 20 21 22 23 |
# File 'lib/eac_config/paths_hash/node.rb', line 16 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
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/eac_config/paths_hash/node.rb', line 25 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
40 41 42 43 44 45 46 47 |
# File 'lib/eac_config/paths_hash/node.rb', line 40 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
36 37 38 |
# File 'lib/eac_config/paths_hash/node.rb', line 36 def to_h data.transform_values { |v| v.is_a?(Node) ? v.to_h : v } end |
#write_entry(path_search, value) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/eac_config/paths_hash/node.rb', line 49 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 |