module Cura::Attributes::HasRoot
Adds the `root` attribute to an object, which defaults to a Component::Group
.
Attributes
Get root component for this object.
@return [Component::Group]
Public Class Methods
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 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 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
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
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
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
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
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
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