Module: Watirsome::Initializers
- Defined in:
- lib/watirsome/initializers.rb
Overview
Initializes page class. Allows to define “#initialize_page” which will be called as page constructor. After page is initialized, iterates through region and initialize each of them.
Instance Method Summary collapse
- #initialize(browser) ⇒ Object
-
#initialize_regions ⇒ Object
Iterates through definitions of “#initialize_region”, thus implementing polymorphic Ruby modules (i.e. page regions).
Instance Method Details
#initialize(browser) ⇒ Object
41 42 43 44 45 |
# File 'lib/watirsome/initializers.rb', line 41 def initialize(browser) @browser = browser initialize_page if respond_to?(:initialize_page) initialize_regions end |
#initialize_regions ⇒ Object
Iterates through definitions of “#initialize_region”, thus implementing polymorphic Ruby modules (i.e. page regions).
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/watirsome/initializers.rb', line 51 def initialize_regions # regions cacher @initialized_regions ||= [] # get included and extended modules modules = self.class.included_modules + (class << self; self end).included_modules modules.uniq! # initialize each module modules.each do |m| # check that constructor is defined and we haven't called it before next if @initialized_regions.include?(m) || !m.instance_methods.include?(:initialize_region) m.instance_method(:initialize_region).bind(self).call # cache region @initialized_regions << m end end |