Class: PageMagic::Elements::Config
- Inherits:
-
CONFIG_STRUCT
- Object
- Struct
- CONFIG_STRUCT
- PageMagic::Elements::Config
- Defined in:
- lib/page_magic/elements/config.rb
Overview
class Config - use to validate input to #elment
Constant Summary collapse
- INVALID_SELECTOR_MSG =
'Pass a locator/define one on the class'
- INVALID_ELEMENT_CLASS_MSG =
'Element class must be of type `PageMagic::Element`'
- TYPE_REQUIRED_MESSAGE =
'element type required'
Instance Attribute Summary
Attributes inherited from CONFIG_STRUCT
#definition_class, #element, #element_class, #name, #options, #type
Class Method Summary collapse
-
.build(args, type) ⇒ Config
Create
Config
used to build instancesPageMagic::Element
seePage::Elements#element
for details.
Instance Method Summary collapse
-
#element_options ⇒ Hash<Symbol,Object>
Options for the building of
PageMagic::Element
viaPageMagic::ElementDefinitionBuilder#new
. -
#selector ⇒ PageMagic::Element::Selector::Model
Selector built using supplied configuration.
-
#validate! ⇒ PageMagic::Elements::Config
Validate supplied configuration.
Class Method Details
.build(args, type) ⇒ Config
Create Config
used to build instances PageMagic::Element
see Page::Elements#element
for details
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/page_magic/elements/config.rb', line 24 def build(args, type) element_class = remove_argument(args, Class) || Element new( name: compute_name(args, element_class), type: type_for(type), selector: compute_selector(args, element_class), options: compute_argument(args, Hash), element: args.delete_at(0), element_class: element_class ) end |
Instance Method Details
#element_options ⇒ Hash<Symbol,Object>
Options for the building of PageMagic::Element
via PageMagic::ElementDefinitionBuilder#new
69 70 71 |
# File 'lib/page_magic/elements/config.rb', line 69 def to_h.except(:element_class, :name, :type, :options).update(selector: selector) end |
#selector ⇒ PageMagic::Element::Selector::Model
Selector built using supplied configuration
75 76 77 78 79 80 |
# File 'lib/page_magic/elements/config.rb', line 75 def selector selector = self[:selector] || definition_class.selector raise PageMagic::InvalidConfigurationException, INVALID_SELECTOR_MSG unless validate_selector?(selector) Element::Selector.find(selector.keys.first).build(type, selector.values.first, options: ) end |
#validate! ⇒ PageMagic::Elements::Config
Validate supplied configuration
85 86 87 88 89 90 |
# File 'lib/page_magic/elements/config.rb', line 85 def validate! raise PageMagic::InvalidConfigurationException, 'element type required' unless type raise PageMagic::InvalidConfigurationException, INVALID_ELEMENT_CLASS_MSG unless valid_element_class? self end |