class Epuber::DSL::TreeObject
Attributes
current_parent_object[RW]
@return [Self]
parent[RW]
@return [self] reference to parent
sub_items[RW]
@return [Array<self>] child items
Public Class Methods
new(parent = nil)
click to toggle source
@param [TreeObject] parent
Calls superclass method
Epuber::DSL::Object::new
# File lib/epuber/dsl/tree_object.rb, line 10 def initialize(parent = nil) super() @parent = parent @sub_items = [] parent.sub_items << self unless parent.nil? end
Public Instance Methods
create_child_item(*args) { |child| ... }
click to toggle source
@yield [child_item] @yieldparam child_item [self] created child item
@return [self]
# File lib/epuber/dsl/tree_object.rb, line 71 def create_child_item(*args) child = self.class.new(*args) parent_object_before = self.class.current_parent_object child.parent = parent_object_before || self child.parent.sub_items << child self.class.current_parent_object = child yield child if block_given? self.class.current_parent_object = parent_object_before child end
create_child_items() { |self| ... }
click to toggle source
@return nil
# File lib/epuber/dsl/tree_object.rb, line 90 def create_child_items yield self if block_given? end
flat_sub_items()
click to toggle source
@return [Array<self>] child items
# File lib/epuber/dsl/tree_object.rb, line 36 def flat_sub_items all = [] sub_items.each do |item| all << item all.concat(item.flat_sub_items) end all end
freeze()
click to toggle source
@return nil
Calls superclass method
Epuber::DSL::Object#freeze
# File lib/epuber/dsl/tree_object.rb, line 21 def freeze super @sub_items.freeze end
root?()
click to toggle source
@return [Bool] receiver is root
# File lib/epuber/dsl/tree_object.rb, line 49 def root? @parent.nil? end
validate()
click to toggle source
@return nil
Calls superclass method
Epuber::DSL::Object#validate
# File lib/epuber/dsl/tree_object.rb, line 55 def validate super sub_items.each(&:validate) end