Module: Liminal::Path

Defined in:
lib/liminal/path.rb

Overview

Utilities for canonical property paths.

Class Method Summary collapse

Class Method Details

.display(path) ⇒ Object

Render a path for diagnostics. Arrays remain the canonical API form.



31
32
33
# File 'lib/liminal/path.rb', line 31

def display(path)
  path.empty? ? "<root>" : path.join(".")
end

.normalize(path) ⇒ Object

Convert an array path, dotted convenience string, or single segment to a frozen array of strings.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/liminal/path.rb', line 10

def normalize(path)
  segments = case path
             when Array then path
             when String then path.split(".", -1)
             when Symbol then [path]
             else
               raise ArgumentError, "path must be an Array, String, or Symbol"
             end

  raise ArgumentError, "path cannot be empty" if segments.empty?

  segments.map do |segment|
    unless segment.is_a?(String) || segment.is_a?(Symbol)
      raise ArgumentError, "path segments must be strings or symbols"
    end

    segment.to_s.dup.freeze
  end.freeze
end