Module: Textus::Protocol::Key

Defined in:
lib/textus/protocol/key.rb,
lib/textus/protocol/key/path.rb,
lib/textus/protocol/key/grammar.rb,
lib/textus/protocol/key/matching.rb

Defined Under Namespace

Modules: Grammar, Matching, Path Classes: Resolution

Class Method Summary collapse

Class Method Details

.match?(pattern, key) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/textus/protocol/key.rb', line 20

def match?(pattern, key)
  Matching.match?(pattern, key)
end

.resolve(key, entries) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/textus/protocol/key.rb', line 8

def resolve(key, entries)
  entry = entries.find { |e| e.key == key }
  return Resolution.new(entry:, remaining: []) if entry

  candidates = entries.select { |e| e.nested? && key.start_with?("#{e.key}.") }
  return nil if candidates.empty?

  best = candidates.max_by { |e| e.key.length }
  tail = key.delete_prefix("#{best.key}.")
  Resolution.new(entry: best, remaining: tail.split("."))
end