Class: PageMagic::ElementContext
- Inherits:
-
Object
- Object
- PageMagic::ElementContext
- Defined in:
- lib/page_magic/element_context.rb
Overview
class ElementContext - resolves which element definition to use when accessing the browser.
Constant Summary collapse
- ELEMENT_NOT_FOUND_MSG =
Message template for execptions raised as a result of calling method_missing
'Unable to find %s'
Instance Attribute Summary collapse
-
#page_element ⇒ Object
readonly
Returns the value of attribute page_element.
Instance Method Summary collapse
-
#initialize(page_element) ⇒ ElementContext
constructor
A new instance of ElementContext.
-
#method_missing(method, *args, &block) ⇒ Object, ...
acts as proxy to element defintions defined on @page_element.
- #respond_to?(*args) ⇒ Boolean
Constructor Details
#initialize(page_element) ⇒ ElementContext
Returns a new instance of ElementContext.
9 10 11 |
# File 'lib/page_magic/element_context.rb', line 9 def initialize(page_element) @page_element = page_element end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object, ...
acts as proxy to element defintions defined on @page_element
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/page_magic/element_context.rb', line 17 def method_missing(method, *args, &block) return page_element.send(method, *args, &block) if page_element.methods.include?(method) builder = page_element.element_by_name(method, *args) prefecteched_element = builder.element return builder.build(prefecteched_element) if prefecteched_element elements = find(builder) elements.size == 1 ? elements.first : elements end |
Instance Attribute Details
#page_element ⇒ Object (readonly)
Returns the value of attribute page_element.
7 8 9 |
# File 'lib/page_magic/element_context.rb', line 7 def page_element @page_element end |
Instance Method Details
#respond_to?(*args) ⇒ Boolean
29 30 31 |
# File 'lib/page_magic/element_context.rb', line 29 def respond_to?(*args) page_element.element_definitions.keys.include?(args.first) end |