Class: Kitchen::Selector

Inherits:
Proc
  • Object
show all
Defined in:
lib/kitchen/selector.rb

Overview

A wrapper for a selector. Can be used as the default_css_or_xpath.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Selector

Returns a new instance of Selector.



14
15
16
17
# File 'lib/kitchen/selector.rb', line 14

def initialize(name, &block)
  @name = name
  super(&block)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/kitchen/selector.rb', line 7

def name
  @name
end

Class Method Details

.named(name) ⇒ Object



9
10
11
12
# File 'lib/kitchen/selector.rb', line 9

def self.named(name)
  @instances ||= {}
  @instances[name] ||= new(name) { |config| config.selectors.send(name) }
end

Instance Method Details

#matches?(node, config:) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/kitchen/selector.rb', line 19

def matches?(node, config:)
  # This may not be incredibly efficient as it does a search of this node's
  # ancestors to see if the node is in the results.  Watch the performance.
  node.quick_matches?(call(config))
end