module Cura::Attributes::HasRoot

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

Attributes

root[R]

Get root component for this object.

@return [Component::Group]

Public Class Methods

new(attributes={}) click to toggle source
Calls superclass method Cura::Attributes::HasAttributes::new
# File lib/cura/attributes/has_root.rb, line 14
def initialize(attributes={})
  @root = Component::Group.new(parent: self)

  super
end

Public Instance Methods

add_child(component_or_type, attributes={}) click to toggle source

Add a child to this object's root component.

@param [#to_sym, Component] component_or_type

A Symbol representing the child component type or a {Component::Base} instance.
When a Symbol is given, a new child component will be initialized of that type. See {Component::Base.type}.

@param [#to_h] attributes

When component_or_type is a Symbol, then these attributes will be used to initialize the child component.
When component_or_type is a {Component::Base}, then these attributes will be used to update the child component.

@return [Component]

# File lib/cura/attributes/has_root.rb, line 54
def add_child(component_or_type, attributes={})
  @root.add_child(component_or_type, attributes)
end
add_children(*children) click to toggle source

Add multiple children to this object's root component.

@param [<Component>] children @return [<Component>]

# File lib/cura/attributes/has_root.rb, line 62
def add_children(*children)
  @root.add_children(*children)
end
children(recursive=false) click to toggle source

Get the children of this object.

@return [<Component>]

# File lib/cura/attributes/has_root.rb, line 41
def children(recursive=false)
  @root.children(recursive)
end
children?() click to toggle source

Determine if this object's root component has children.

@return [Boolean]

# File lib/cura/attributes/has_root.rb, line 92
def children?
  @root.children?
end
delete_child(component) click to toggle source

Remove a child from this object's root component.

@param [Component] component @return [Component]

# File lib/cura/attributes/has_root.rb, line 78
def delete_child(component)
  @root.delete_child(component)
end
delete_child_at(index) click to toggle source

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

@param [Integer] index @return [Component]

# File lib/cura/attributes/has_root.rb, line 70
def delete_child_at(index)
  @root.delete_child_at(index)
end
delete_children() click to toggle source

Remove all children from object's root component.

@return [HasChildren]

# File lib/cura/attributes/has_root.rb, line 85
def delete_children
  @root.delete_children
end
root=(value) click to toggle source

Set root component for this object.

@param [Component::Group] component @return [Component::Group]

# File lib/cura/attributes/has_root.rb, line 29
def root=(value)
  raise TypeError, "root must be a Component::Group" unless value.is_a?(Component::Group)

  @root = value
end