Module: SitePrism::ElementContainer::ClassMethods

Defined in:
lib/site_prism/element_container.rb

Overview

rubocop:disable Metrics/ModuleLength

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#expected_itemsObject (readonly)

Returns the value of attribute expected_items.



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

def expected_items
  @expected_items
end

#mapped_itemsObject (readonly)

Returns the value of attribute mapped_items.



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

def mapped_items
  @mapped_items
end

Instance Method Details

#add_to_mapped_items(item) ⇒ Object



127
128
129
130
# File 'lib/site_prism/element_container.rb', line 127

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

#collection(name, *find_args) ⇒ Object



81
82
83
84
85
# File 'lib/site_prism/element_container.rb', line 81

def collection(name, *find_args)
  warn 'Using collection is now deprecated and will be removed.'
  warn 'Use elements DSL notation instead.'
  elements(name, *find_args)
end

#element(name, *find_args) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/site_prism/element_container.rb', line 63

def element(name, *find_args)
  build(name, *find_args) do
    define_method(name) do |*runtime_args, &element_block|
      raise_if_block(self, name, !element_block.nil?, :element)
      _find(*merge_args(find_args, runtime_args))
    end
  end
end

#elements(name, *find_args) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/site_prism/element_container.rb', line 72

def elements(name, *find_args)
  build(name, *find_args) do
    define_method(name) do |*runtime_args, &element_block|
      raise_if_block(self, name, !element_block.nil?, :elements)
      _all(*merge_args(find_args, runtime_args))
    end
  end
end

#expected_elements(*elements) ⇒ Object



87
88
89
# File 'lib/site_prism/element_container.rb', line 87

def expected_elements(*elements)
  @expected_items = elements
end

#iframe(name, klass, *args) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/site_prism/element_container.rb', line 113

def iframe(name, klass, *args)
  element_find_args = deduce_iframe_element_find_args(args)
  scope_find_args = deduce_iframe_scope_find_args(args)
  add_to_mapped_items(name)
  add_iframe_helper_methods(name, *element_find_args)
  define_method(name) do |&block|
    raise BlockMissingError unless block

    within_frame(*scope_find_args) do
      block.call(klass.new)
    end
  end
end

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



91
92
93
94
95
96
97
98
99
# File 'lib/site_prism/element_container.rb', line 91

def section(name, *args, &block)
  section_class, find_args = extract_section_options(args, &block)
  build(name, *find_args) do
    define_method(name) do |*runtime_args, &runtime_block|
      section_element = _find(*merge_args(find_args, runtime_args))
      section_class.new(self, section_element, &runtime_block)
    end
  end
end

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



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/site_prism/element_container.rb', line 101

def sections(name, *args, &block)
  section_class, find_args = extract_section_options(args, &block)
  build(name, *find_args) do
    define_method(name) do |*runtime_args, &element_block|
      raise_if_block(self, name, !element_block.nil?, :sections)
      _all(*merge_args(find_args, runtime_args)).map do |element|
        section_class.new(self, element)
      end
    end
  end
end