Module: SitePrism::ElementContainer

Included in:
Page, Section
Defined in:
lib/site_prism/element_container.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#mapped_itemsObject (readonly)

Returns the value of attribute mapped_items


3
4
5
# File 'lib/site_prism/element_container.rb', line 3

def mapped_items
  @mapped_items
end

Instance Method Details

#add_to_mapped_items(item) ⇒ Object


60
61
62
63
# File 'lib/site_prism/element_container.rb', line 60

def add_to_mapped_items(item)
  @mapped_items ||= []
  @mapped_items << item.to_s
end

#element(element_name, *find_args) ⇒ Object


5
6
7
8
9
10
11
12
# File 'lib/site_prism/element_container.rb', line 5

def element(element_name, *find_args)
  build element_name, *find_args do
    define_method element_name.to_s do |*runtime_args, &element_block|
      self.class.raise_if_block(self, element_name.to_s, !element_block.nil?)
      find_first(*find_args, *runtime_args)
    end
  end
end

#elements(collection_name, *find_args) ⇒ Object Also known as: collection


14
15
16
17
18
19
20
21
# File 'lib/site_prism/element_container.rb', line 14

def elements(collection_name, *find_args)
  build collection_name, *find_args do
    define_method collection_name.to_s do |*runtime_args, &element_block|
      self.class.raise_if_block(self, collection_name.to_s, !element_block.nil?)
      find_all(*find_args, *runtime_args)
    end
  end
end

#iframe(iframe_name, iframe_page_class, selector) ⇒ Object


46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/site_prism/element_container.rb', line 46

def iframe(iframe_name, iframe_page_class, selector)
  element_selector = deduce_iframe_element_selector(selector)
  scope_selector = deduce_iframe_scope_selector(selector)
  add_to_mapped_items iframe_name
  create_existence_checker iframe_name, element_selector
  create_nonexistence_checker iframe_name, element_selector
  create_waiter iframe_name, element_selector
  define_method iframe_name do |&block|
    within_frame scope_selector do
      block.call iframe_page_class.new
    end
  end
end

#raise_if_block(obj, name, has_block) ⇒ Object


65
66
67
68
# File 'lib/site_prism/element_container.rb', line 65

def raise_if_block(obj, name, has_block)
  return unless has_block
  fail SitePrism::UnsupportedBlock, "#{obj.class}##{name} does not accept blocks, did you mean to define a (i)frame?"
end

#section(section_name, *args, &block) ⇒ Object


24
25
26
27
28
29
30
31
32
# File 'lib/site_prism/element_container.rb', line 24

def section(section_name, *args, &block)
  section_class, find_args = extract_section_options args, &block
  build section_name, *find_args do
    define_method section_name do |*runtime_args, &element_block|
      self.class.raise_if_block(self, section_name.to_s, !element_block.nil?)
      section_class.new self, find_first(*find_args, *runtime_args)
    end
  end
end

#sections(section_collection_name, *args, &block) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
# File 'lib/site_prism/element_container.rb', line 34

def sections(section_collection_name, *args, &block)
  section_class, find_args = extract_section_options args, &block
  build section_collection_name, *find_args do
    define_method section_collection_name do |*runtime_args, &element_block|
      self.class.raise_if_block(self, section_collection_name.to_s, !element_block.nil?)
      find_all(*find_args, *runtime_args).map do |element|
        section_class.new self, element
      end
    end
  end
end