Class: Ace::Support::Cli::Registry::NestedRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/cli/registry.rb

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ NestedRegistry

Returns a new instance of NestedRegistry.



67
68
69
# File 'lib/ace/support/cli/registry.rb', line 67

def initialize(node)
  @node = node
end

Instance Method Details

#register(name, command_class = nil) {|NestedRegistry.new(node)| ... } ⇒ Object

Yields:

Raises:

  • (ArgumentError)


71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ace/support/cli/registry.rb', line 71

def register(name, command_class = nil)
  parts = name.to_s.split(" ")
  raise ArgumentError, "Command name cannot be empty" if parts.empty?

  node = parts.reduce(@node) do |current, part|
    current.children[part] ||= Node.new(nil, {})
  end
  node.command = command_class if command_class
  yield NestedRegistry.new(node) if block_given?
  self
end