Class: Chemlab::Component

Inherits:
Object
  • Object
show all
Extended by:
SingleForwardable
Defined in:
lib/chemlab/component.rb

Overview

The base representation of any UI component.

Direct Known Subclasses

Page

Defined Under Namespace

Classes: DSL

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.perform {|new| ... } ⇒ Object

Perform actions against the given page

Examples:

Component.perform do |component|
  component.do_something
end
Component.perform(&:do_something)

Yields:

  • (new)

Returns:

  • The instance of Component used to perform the action



21
22
23
# File 'lib/chemlab/component.rb', line 21

def self.perform
  yield new if block_given?
end

.public_elementsArray

Elements defined on the page

Examples:

+text_field :username, id: 'username'+
Will be in form:
  {
    type: :text_field,
    name: :username,
    args: [ { id: 'username' } ]
  }

Returns:

  • (Array)


36
37
38
# File 'lib/chemlab/component.rb', line 36

def public_elements
  @public_elements ||= []
end

Instance Method Details

#visible?Boolean

Note:

The page presence is determined by the elements defined on the page and their requirement

If this component is currently visible

Returns:

  • (Boolean)

    true if the defined elements in the library are present



88
89
90
91
92
93
94
95
96
# File 'lib/chemlab/component.rb', line 88

def visible?
  missing_elements = [] + self.class.public_elements

  self.class.public_elements.each do |element|
    missing_elements.shift if has_element?(element[:type], element[:name], element[:args].first)
  end

  missing_elements.none?
end