Class: Dry::CLI::CommandRegistry::Node Private
- Inherits:
-
Object
- Object
- Dry::CLI::CommandRegistry::Node
- Defined in:
- lib/dry/cli/command_registry.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Node of the registry
Instance Attribute Summary collapse
- #after_callbacks ⇒ Object readonly private
- #aliases ⇒ Object readonly private
- #before_callbacks ⇒ Object readonly private
- #children ⇒ Object readonly private
- #command ⇒ Object readonly private
- #parent ⇒ Object readonly private
Instance Method Summary collapse
- #alias!(key, child) ⇒ Object private
- #aliases!(aliases) ⇒ Object private
- #children? ⇒ Boolean private
-
#initialize(parent = nil) ⇒ Node
constructor
private
A new instance of Node.
- #leaf!(command) ⇒ Object private
- #leaf? ⇒ Boolean private
- #lookup(token) ⇒ Object private
- #put(parent, key) ⇒ Object private
- #subcommands!(command) ⇒ Object private
Constructor Details
#initialize(parent = nil) ⇒ Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Node.
108 109 110 111 112 113 114 115 116 |
# File 'lib/dry/cli/command_registry.rb', line 108 def initialize(parent = nil) @parent = parent @children = {} @aliases = {} @command = nil @before_callbacks = Chain.new @after_callbacks = Chain.new end |
Instance Attribute Details
#after_callbacks ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
104 105 106 |
# File 'lib/dry/cli/command_registry.rb', line 104 def after_callbacks @after_callbacks end |
#aliases ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
92 93 94 |
# File 'lib/dry/cli/command_registry.rb', line 92 def aliases @aliases end |
#before_callbacks ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
100 101 102 |
# File 'lib/dry/cli/command_registry.rb', line 100 def before_callbacks @before_callbacks end |
#children ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
88 89 90 |
# File 'lib/dry/cli/command_registry.rb', line 88 def children @children end |
#command ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
96 97 98 |
# File 'lib/dry/cli/command_registry.rb', line 96 def command @command end |
#parent ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
84 85 86 |
# File 'lib/dry/cli/command_registry.rb', line 84 def parent @parent end |
Instance Method Details
#alias!(key, child) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
145 146 147 |
# File 'lib/dry/cli/command_registry.rb', line 145 def alias!(key, child) @aliases[key] = child end |
#aliases!(aliases) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
151 152 153 154 155 |
# File 'lib/dry/cli/command_registry.rb', line 151 def aliases!(aliases) aliases.each do |a| parent.alias!(a, self) end end |
#children? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
165 166 167 |
# File 'lib/dry/cli/command_registry.rb', line 165 def children? children.any? end |
#leaf!(command) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
132 133 134 |
# File 'lib/dry/cli/command_registry.rb', line 132 def leaf!(command) @command = command end |
#leaf? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
159 160 161 |
# File 'lib/dry/cli/command_registry.rb', line 159 def leaf? !command.nil? end |
#lookup(token) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
126 127 128 |
# File 'lib/dry/cli/command_registry.rb', line 126 def lookup(token) children[token] || aliases[token] end |
#put(parent, key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
120 121 122 |
# File 'lib/dry/cli/command_registry.rb', line 120 def put(parent, key) children[key] ||= self.class.new(parent) end |
#subcommands!(command) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
138 139 140 141 |
# File 'lib/dry/cli/command_registry.rb', line 138 def subcommands!(command) command_class = command.is_a?(Class) ? command : command.class command_class.subcommands = children end |