Module: AePageObjects::Dsl
Instance Method Summary collapse
-
#collection(name, options = {}, &block) ⇒ Object
Defines a collection of elements.
- #element(name, options = {}, &block) ⇒ Object
- #element_attributes ⇒ Object
- #form_for(form_name, options = {}, &block) ⇒ Object
- #inherited(subclass) ⇒ Object
- #is_loaded(&block) ⇒ Object
- #is_loaded_blocks ⇒ Object
Methods included from InternalHelpers
Instance Method Details
#collection(name, options = {}, &block) ⇒ Object
Defines a collection of elements. Blocks are evaluated on the item class used by the collection. collection() defines a method on the class that returns an instance of a collection class which contains instances of the collection’s item class.
Supported signatures are described below.
Signature: (no :is, no :contains, no block)
collection :addresses
Collection class: Collection
Item class: Element
Signature: (no :is, no :contains, block)
collection :addresses do
element :city
element :state
end
Collection class: one-off subclass of Collection
Item class: one-off subclass of Element
Methods defined on item class:
city() # -> instance of Element
state() # -> instance of Element
Signature: (no :is, :contains, no block)
collection :addresses, :contains => Address
Collection class: one-off subclass of Collection
Item class: Address
Signature: (no :is, :contains, block)
collection :addresses, :contains => Address do
element :longitude
element :latitude
end
Collection class: one-off subclass of Collection element
Item class: one-off subclass of Address
Methods defined on item class:
longitude() # -> instance of Element
latitude() # -> instance of Element
Signature: (:is, no :contains, no block)
collection :addresses, :is => AddressList
Collection class: AddressList
Item class: AddressList.item_class
Signature: (:is, no :contains, block)
collection :addresses, :is => AddressList do
element :longitude
element :latitude
end
Collection class: one-off subclass of AddressList
Item class: one-off subclass of AddressList.item_class
Methods defined on item class:
longitude() # -> instance of Element
latitude() # -> instance of Element
Signature: (:is, :contains, no block)
collection :addresses, :is => AddressList, :contains => ExtendedAddress
Collection class: one-off subclass ofAddressList
Item class: ExtendedAddress
Signature: (:is, :contains, block)
collection :addresses, :is => AddressList, :contains => Address do
element :longitude
element :latitude
end
Collection class: one-off subclass of AddressList
Item class: one-off subclass of Address
Methods defined on item class:
longitude() # -> instance of Element
latitude() # -> instance of Element
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/ae_page_objects/core/dsl.rb', line 140 def collection(name, = {}, &block) ||= {} # only a collection class is specified or the item class # specified matches the collection's item class if ! block_given? && [:is] && ( [:contains].nil? || [:is].item_class == [:contains] ) return element(name, ) end = .dup # create/get the collection class if [:is] ensure_class_for_param!(:is, [:is], Collection) else [:is] = Collection end item_class = .delete(:contains) || [:is].item_class if block_given? item_class = Class.new(item_class, &block).tap do |new_item_class| new_item_class.element_attributes.merge!(item_class.element_attributes) end end # since we are creating a new item class, we need to subclass the collection class # so we can parameterize the collection class with an item class [:is] = Class.new([:is]) [:is].item_class = item_class element(name, ) end |
#element(name, options = {}, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ae_page_objects/core/dsl.rb', line 26 def element(name, = {}, &block) = .dup [:name] ||= name [:is] ||= Element if block_given? [:is] = Class.new([:is], &block) end element_class = [:is] self.element_attributes[name.to_sym] = element_class define_method name do self.element() end element_class end |
#element_attributes ⇒ Object
14 15 16 |
# File 'lib/ae_page_objects/core/dsl.rb', line 14 def element_attributes @element_attributes ||= {} end |
#form_for(form_name, options = {}, &block) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/ae_page_objects/core/dsl.rb', line 175 def form_for(form_name, = {}, &block) ||= {} raise ArgumentError, ":is option not supported" if [:is] raise ArgumentError, "Block required." if block.nil? klass = Class.new(Form, &block) = .dup [:is] = klass element(form_name, ) klass.element_attributes.each do |element_name, element_klazz| class_eval <<-RUBY def #{element_name}(*args, &block) #{form_name}.#{element_name}(*args, &block) end RUBY self.element_attributes[element_name] = element_klazz end end |
#inherited(subclass) ⇒ Object
8 9 10 11 12 |
# File 'lib/ae_page_objects/core/dsl.rb', line 8 def inherited(subclass) super subclass.is_loaded_blocks.push(*is_loaded_blocks) end |
#is_loaded(&block) ⇒ Object
22 23 24 |
# File 'lib/ae_page_objects/core/dsl.rb', line 22 def is_loaded(&block) self.is_loaded_blocks << block end |
#is_loaded_blocks ⇒ Object
18 19 20 |
# File 'lib/ae_page_objects/core/dsl.rb', line 18 def is_loaded_blocks @is_loaded_blocks ||= [] end |