Class: AutomationObject::Composite
- Inherits:
-
Object
- Object
- AutomationObject::Composite
- Includes:
- CompositeHook, Reflection
- Defined in:
- lib/automation_object/helpers/composite.rb
Overview
Composite is a super class that helps build composite objects based of a Hash Composite classes should inherit from this class and use the class-level methods to add the components
Direct Known Subclasses
BluePrint::HashAdapter::Composite, BluePrint::PageObjectAdapter::Composite, State::Base
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#location ⇒ Object
Returns the value of attribute location.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
Class Method Summary collapse
-
.has_many(children_name, args) ⇒ Object
Has many children relationship for the composite.
-
.has_many_relationships ⇒ Hash
Relationships for the composite.
- .has_one(child_name, args) ⇒ Object
-
.has_one_relationships ⇒ Hash
Hash of relationships.
Instance Method Summary collapse
- #add_has_many_relationships ⇒ Object
- #add_has_one_relationships ⇒ Object
-
#get_child(_name, _options) ⇒ Object
Abstract argument, override.
-
#get_children(_name, _options) ⇒ Object
Abstract argument, override.
-
#initialize(name = :top, parent = nil, location = 'top') ⇒ Composite
constructor
A new instance of Composite.
-
#top ⇒ AutomationObject::Composite
Get top composite Object.
Methods included from Reflection
Methods included from CompositeHook
#after_create_run, #before_create_run, included
Constructor Details
#initialize(name = :top, parent = nil, location = 'top') ⇒ Composite
Returns a new instance of Composite
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/automation_object/helpers/composite.rb', line 18 def initialize(name = :top, parent = nil, location = 'top') self.name = name self.parent = parent self.location = location before_create_run add_has_one_relationships add_has_many_relationships after_create_run end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children
13 14 15 |
# File 'lib/automation_object/helpers/composite.rb', line 13 def children @children end |
#location ⇒ Object
Returns the value of attribute location
13 14 15 |
# File 'lib/automation_object/helpers/composite.rb', line 13 def location @location end |
#name ⇒ Object
Returns the value of attribute name
13 14 15 |
# File 'lib/automation_object/helpers/composite.rb', line 13 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent
13 14 15 |
# File 'lib/automation_object/helpers/composite.rb', line 13 def parent @parent end |
Class Method Details
.has_many(children_name, args) ⇒ Object
Has many children relationship for the composite
79 80 81 |
# File 'lib/automation_object/helpers/composite.rb', line 79 def has_many(children_name, args) has_many_relationships[children_name] = args end |
.has_many_relationships ⇒ Hash
Returns relationships for the composite
84 85 86 |
# File 'lib/automation_object/helpers/composite.rb', line 84 def has_many_relationships @has_many_relationships ||= {} end |
.has_one(child_name, args) ⇒ Object
90 91 92 |
# File 'lib/automation_object/helpers/composite.rb', line 90 def has_one(child_name, args) has_one_relationships[child_name] = args end |
.has_one_relationships ⇒ Hash
Returns hash of relationships
95 96 97 |
# File 'lib/automation_object/helpers/composite.rb', line 95 def has_one_relationships @has_one_relationships ||= {} end |
Instance Method Details
#add_has_many_relationships ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/automation_object/helpers/composite.rb', line 67 def add_has_many_relationships self.class.has_many_relationships.each do |name, | composite_children = get_children(name, ) children[name] = composite_children add_attribute(name, children[name]) end end |
#add_has_one_relationships ⇒ Object
60 61 62 63 64 65 |
# File 'lib/automation_object/helpers/composite.rb', line 60 def add_has_one_relationships self.class.has_one_relationships.each do |name, | children[name] = get_child(name, ) add_attribute(name, children[name]) end end |
#get_child(_name, _options) ⇒ Object
Abstract argument, override
48 49 50 |
# File 'lib/automation_object/helpers/composite.rb', line 48 def get_child(_name, ) raise 'Abstract method' end |
#get_children(_name, _options) ⇒ Object
Abstract argument, override
56 57 58 |
# File 'lib/automation_object/helpers/composite.rb', line 56 def get_children(_name, ) raise 'Abstract method' end |
#top ⇒ AutomationObject::Composite
Get top composite Object
39 40 41 42 |
# File 'lib/automation_object/helpers/composite.rb', line 39 def top # Should recursively call top until parent is nil parent.nil? ? self : parent.top end |