Class: Taketo::NodeResolver
- Inherits:
-
Object
- Object
- Taketo::NodeResolver
show all
- Defined in:
- lib/taketo/node_resolver.rb
Instance Method Summary
collapse
Constructor Details
#initialize(config, path) ⇒ NodeResolver
Returns a new instance of NodeResolver.
10
11
12
13
14
15
16
17
|
# File 'lib/taketo/node_resolver.rb', line 10
def initialize(config, path)
@config = config
if String(path).empty? && !String(config.default_destination).empty?
path = config.default_destination
end
@path = path
@traverser = ConfigTraverser.new(@config)
end
|
Instance Method Details
#disambiguate(results) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/taketo/node_resolver.rb', line 36
def disambiguate(results)
case results.length
when 0
raise NonExistentDestinationError, "Can't find such destination: #@path"
when 1
results.first
else
exact_match = results.detect { |n| n.path == @path }
exact_match or raise AmbiguousDestinationError,
"There are multiple possible destinations: #{results.map(&:path).join(", ")}"
end
end
|
#resolve ⇒ Object
19
20
21
|
# File 'lib/taketo/node_resolver.rb', line 19
def resolve
resolve_by_path
end
|
#resolve_by_path ⇒ Object
23
24
25
26
|
# File 'lib/taketo/node_resolver.rb', line 23
def resolve_by_path
matching_nodes = nodes.select { |n| n.path == @path }
disambiguate(matching_nodes)
end
|