class Taketo::NodeResolver
Public Class Methods
new(config, path)
click to toggle source
# 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
Public Instance Methods
disambiguate(results)
click to toggle source
# 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
nodes()
click to toggle source
# File lib/taketo/node_resolver.rb, line 28 def nodes @nodes ||= begin collector = SimpleCollector(Taketo::Constructs::BaseConstruct).new @traverser.visit_depth_first(collector) collector.result.reject { |n| Taketo::Constructs::Command === n } end end
resolve()
click to toggle source
# File lib/taketo/node_resolver.rb, line 19 def resolve resolve_by_path end
resolve_by_path()
click to toggle source
# File lib/taketo/node_resolver.rb, line 23 def resolve_by_path matching_nodes = nodes.select { |n| n.path == @path } disambiguate(matching_nodes) end