class Shelley::CommandNode

A node of the command tree

Attributes

children[R]
command[RW]
name[RW]
parent[R]

Public Class Methods

new(parent = nil) click to toggle source
# File lib/shelley/registry.rb, line 8
def initialize(parent = nil)
  @children = []
  @parent = parent
end

Public Instance Methods

ensure_exists(*path) click to toggle source
# File lib/shelley/registry.rb, line 13
def ensure_exists(*path)
  return self if path.count.zero?
  curr_name = path.shift
  node = @children.find { |n| n.name == curr_name }
  if node.nil?
    node = CommandNode.new(self)
    node.name = curr_name
    @children << node
  end
  return node if path.count.zero?
  node.ensure_exists(*path)
end
full_path() click to toggle source
# File lib/shelley/registry.rb, line 35
def full_path
  curr_node = self
  path = []
  until curr_node.parent.nil?
    path << curr_node.name
    curr_node = curr_node.parent
  end
  path.reverse
end
node_by_path(*path) click to toggle source
# File lib/shelley/registry.rb, line 26
def node_by_path(*path)
  return self if path.count.zero?
  curr_name = path.shift
  node = @children.find { |n| n.name == curr_name }
  return nil if node.nil?
  return node if path.count.zero?
  node.node_by_path(*path)
end
to_s() click to toggle source
# File lib/shelley/registry.rb, line 45
def to_s
  "CommandNode(name=#{name}, command=#{command}, children={#{children.map(&:to_s)}})"
end