Class: Textus::Protocol::Links::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/protocol/links/resolver.rb

Defined Under Namespace

Classes: UnknownKeyError

Instance Method Summary collapse

Constructor Details

#initialize(manifest:) ⇒ Resolver

Returns a new instance of Resolver.



10
11
12
# File 'lib/textus/protocol/links/resolver.rb', line 10

def initialize(manifest:)
  @manifest = manifest
end

Instance Method Details

#resolve(key:, from_path:) ⇒ Object

Raises:



14
15
16
17
18
19
20
21
22
# File 'lib/textus/protocol/links/resolver.rb', line 14

def resolve(key:, from_path:)
  entry = @manifest.data.entries.find { |e| e.key == key }
  raise UnknownKeyError.new("unknown key: #{key}") unless entry

  to = Array(entry.publish_to).first
  return "`textus get #{key}`" if to.nil?

  relative_path(from: from_path, to: to)
end