Module: Cura::Attributes::HasRoot

Includes:
HasAttributes
Included in:
Window
Defined in:
lib/cura/attributes/has_root.rb

Overview

Adds the ‘root` attribute to an object, which defaults to a Component::Group.

Instance Method Summary collapse

Methods included from HasAttributes

included, #update_attributes

Instance Method Details

#add_child(component) ⇒ Component

Add a child to this object’s root component.

Parameters:

Returns:



47
48
49
# File 'lib/cura/attributes/has_root.rb', line 47

def add_child(component)
  @root.add_child(component)
end

#add_children(*children) ⇒ <Component>

Add multiple children to this object’s root component.

Parameters:

Returns:



55
56
57
# File 'lib/cura/attributes/has_root.rb', line 55

def add_children(*children)
  @root.add_children(*children)
end

#children(recursive = false) ⇒ <Component>

Get the children of this object.

Returns:



39
40
41
# File 'lib/cura/attributes/has_root.rb', line 39

def children(recursive=false)
  @root.children(recursive)
end

#children?Boolean

Determine if this object’s root component has children.

Returns:

  • (Boolean)


85
86
87
# File 'lib/cura/attributes/has_root.rb', line 85

def children?
  @root.children?
end

#delete_child(component) ⇒ Component

Remove a child from this object’s root component.

Parameters:

Returns:



71
72
73
# File 'lib/cura/attributes/has_root.rb', line 71

def delete_child(component)
  @root.delete_child(component)
end

#delete_child_at(index) ⇒ Component

Remove a child from object’s root component at the given index.

Parameters:

  • index (Integer)

Returns:



63
64
65
# File 'lib/cura/attributes/has_root.rb', line 63

def delete_child_at(index)
  @root.delete_child_at(index)
end

#delete_childrenHasChildren

Remove all children from object’s root component.

Returns:



78
79
80
# File 'lib/cura/attributes/has_root.rb', line 78

def delete_children
  @root.delete_children
end

#initialize(attributes = {}) ⇒ Object



15
16
17
18
19
# File 'lib/cura/attributes/has_root.rb', line 15

def initialize(attributes={})
  @root = Component::Group.new(parent: self)
  
  super
end

#rootComponent::Group

Get root component for this object.

Returns:



# File 'lib/cura/attributes/has_root.rb', line 21

#root=(component) ⇒ Component::Group

Set root component for this object.

Parameters:

Returns:



32
# File 'lib/cura/attributes/has_root.rb', line 32

attribute(:root) { |component| set_root(component) }