Class: EacConfig::PathsHash
- Inherits:
-
Object
- Object
- EacConfig::PathsHash
- Defined in:
- lib/eac_config/paths_hash.rb,
lib/eac_config/paths_hash/node.rb,
lib/eac_config/paths_hash/path_search.rb,
lib/eac_config/paths_hash/entry_key_error.rb
Defined Under Namespace
Classes: EntryKeyError, Node, PathSearch
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
-
.parse_entry_key(entry_key) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
Instance Method Summary collapse
- #[](entry_key) ⇒ Object
- #[]=(entry_key, entry_value) ⇒ Object
- #fetch(entry_key) ⇒ Object
-
#initialize(source_hash = {}) ⇒ PathsHash
constructor
A new instance of PathsHash.
- #key?(entry_key) ⇒ Boolean
-
#write(entry_key, entry_value) ⇒ EacConfig::PathsHash
EacConfig::PathsHash.
Constructor Details
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
26 27 28 |
# File 'lib/eac_config/paths_hash.rb', line 26 def root @root end |
Class Method Details
.parse_entry_key(entry_key) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/eac_config/paths_hash.rb', line 10 def parse_entry_key(entry_key) # rubocop:disable Metrics/CyclomaticComplexity r = entry_key.to_s.strip raise ::EacConfig::PathsHash::EntryKeyError, 'Entry key cannot start or end with dot' if r.start_with?('.') || r.end_with?('.') r = r.split('.').map(&:strip) if r.empty? raise ::EacConfig::PathsHash::EntryKeyError, "Entry key \"#{entry_key}\" is empty" end return r.map(&:to_sym) unless r.any?(&:blank?) raise ::EacConfig::PathsHash::EntryKeyError, "Entry key \"#{entry_key}\" has at least one blank part" end |
Instance Method Details
#[](entry_key) ⇒ Object
32 33 34 |
# File 'lib/eac_config/paths_hash.rb', line 32 def [](entry_key) root.read_entry(::EacConfig::PathsHash::PathSearch.parse_entry_key(entry_key)) end |
#[]=(entry_key, entry_value) ⇒ Object
36 37 38 39 40 |
# File 'lib/eac_config/paths_hash.rb', line 36 def []=(entry_key, entry_value) root.write_entry( ::EacConfig::PathsHash::PathSearch.parse_entry_key(entry_key), entry_value ) end |
#fetch(entry_key) ⇒ Object
42 43 44 |
# File 'lib/eac_config/paths_hash.rb', line 42 def fetch(entry_key) root.fetch(::EacConfig::PathsHash::PathSearch.parse_entry_key(entry_key)) end |
#key?(entry_key) ⇒ Boolean
46 47 48 |
# File 'lib/eac_config/paths_hash.rb', line 46 def key?(entry_key) root.entry?(::EacConfig::PathsHash::PathSearch.parse_entry_key(entry_key)) end |
#write(entry_key, entry_value) ⇒ EacConfig::PathsHash
Returns EacConfig::PathsHash.
53 54 55 56 57 |
# File 'lib/eac_config/paths_hash.rb', line 53 def write(entry_key, entry_value) self[entry_key] = entry_value self end |