Class: PageMagic::Element::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/page_magic/element/query.rb,
lib/page_magic/element/query/single_result.rb,
lib/page_magic/element/query/multiple_results.rb,
lib/page_magic/element/query/prefetched_result.rb

Overview

class Query - executes query on capybara driver

Direct Known Subclasses

MultipleResults, PrefetchedResult, SingleResult

Defined Under Namespace

Classes: MultipleResults, PrefetchedResult, SingleResult

Constant Summary collapse

DEFAULT_DECORATOR =
proc { |arg| arg }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*selector_args, options: {}) ⇒ Query

Returns a new instance of Query.



14
15
16
17
# File 'lib/page_magic/element/query.rb', line 14

def initialize(*selector_args, options: {})
  @selector_args = selector_args
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/page_magic/element/query.rb', line 10

def options
  @options
end

#selector_argsObject (readonly)

Returns the value of attribute selector_args.



10
11
12
# File 'lib/page_magic/element/query.rb', line 10

def selector_args
  @selector_args
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
# File 'lib/page_magic/element/query.rb', line 31

def ==(other)
  other.respond_to?(:selector_args) && selector_args == other.selector_args &&
    other.respond_to?(:options) && options == other.options
end

#execute(capybara_element, &block) ⇒ Array<Capybara::Node::Element>, NullElement

TODO: - test for decoration? Run query against the scope of the given element The supplied block will be used to decorate the results

Parameters:

  • capybara_element (Capybara::Node::Element)

    the element to be searched within

Returns:

  • (Array<Capybara::Node::Element>)

    the results

  • (NullElement)

    when the element is not found



25
26
27
28
29
# File 'lib/page_magic/element/query.rb', line 25

def execute(capybara_element, &block)
  find(capybara_element, &(block || DEFAULT_DECORATOR))
rescue Capybara::ElementNotFound => e
  NotFound.new(e)
end