Class: EacConfig::EntryPath
- Inherits:
-
Object
- Object
- EacConfig::EntryPath
- Defined in:
- lib/eac_config/entry_path.rb
Constant Summary collapse
- PART_SEPARATOR =
'.'
Instance Attribute Summary collapse
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(parts) ⇒ EntryPath
constructor
A new instance of EntryPath.
- #to_s ⇒ Object
Constructor Details
#initialize(parts) ⇒ EntryPath
Returns a new instance of EntryPath.
33 34 35 |
# File 'lib/eac_config/entry_path.rb', line 33 def initialize(parts) @parts = parts.to_a.freeze end |
Instance Attribute Details
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
31 32 33 |
# File 'lib/eac_config/entry_path.rb', line 31 def parts @parts end |
Class Method Details
.assert(source) ⇒ Object
10 11 12 |
# File 'lib/eac_config/entry_path.rb', line 10 def assert(source) source.is_a?(self) ? source : new(build_parts(source)) end |
.build_parts(source) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/eac_config/entry_path.rb', line 14 def build_parts(source) return validate_parts!(source.split(PART_SEPARATOR)) if source.is_a?(::String) return validate_parts!(source.flat_map { |part| build_parts(part) }) if source.is_a?(::Enumerable) build_parts(source.to_s) end |
.validate_parts!(parts) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/eac_config/entry_path.rb', line 22 def validate_parts!(parts) parts.assert_argument(::Enumerable, 'parts') parts.each_with_index do |part, index| raise ::ArgumentError, "Part #{index} of #{parts} is blank" if part.blank? raise ::ArgumentError, "Part #{index} is not a string" unless part.is_a?(::String) end end |
Instance Method Details
#to_s ⇒ Object
37 38 39 |
# File 'lib/eac_config/entry_path.rb', line 37 def to_s "#{self.class}[#{parts.join(PART_SEPARATOR)}]" end |