Class: Dry::CLI::CommandRegistry::Node Private

Inherits:
Object
  • Object
show all
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

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Since:

  • 0.1.0



113
114
115
116
117
118
119
120
121
122
# File 'lib/dry/cli/command_registry.rb', line 113

def initialize(parent = nil)
  @parent   = parent
  @children = {}
  @aliases  = {}
  @hidden   = hidden
  @command  = nil

  @before_callbacks = Chain.new
  @after_callbacks = Chain.new
end

Instance Attribute Details

#after_callbacksObject (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.

Since:

  • 0.1.0



109
110
111
# File 'lib/dry/cli/command_registry.rb', line 109

def after_callbacks
  @after_callbacks
end

#aliasesObject (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.

Since:

  • 0.1.0



93
94
95
# File 'lib/dry/cli/command_registry.rb', line 93

def aliases
  @aliases
end

#before_callbacksObject (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.

Since:

  • 0.1.0



105
106
107
# File 'lib/dry/cli/command_registry.rb', line 105

def before_callbacks
  @before_callbacks
end

#childrenObject (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.

Since:

  • 0.1.0



89
90
91
# File 'lib/dry/cli/command_registry.rb', line 89

def children
  @children
end

#commandObject (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.

Since:

  • 0.1.0



101
102
103
# File 'lib/dry/cli/command_registry.rb', line 101

def command
  @command
end

#hiddenObject (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.

Since:

  • 1.1.1



97
98
99
# File 'lib/dry/cli/command_registry.rb', line 97

def hidden
  @hidden
end

#parentObject (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.

Since:

  • 0.1.0



85
86
87
# File 'lib/dry/cli/command_registry.rb', line 85

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.

Since:

  • 0.1.0



151
152
153
# File 'lib/dry/cli/command_registry.rb', line 151

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.

Since:

  • 0.1.0



157
158
159
160
161
# File 'lib/dry/cli/command_registry.rb', line 157

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.

Returns:

  • (Boolean)

Since:

  • 0.7.0



177
178
179
# File 'lib/dry/cli/command_registry.rb', line 177

def children?
  children.any?
end

#hidden!(hidden) ⇒ 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.

Since:

  • 1.1.1



165
166
167
# File 'lib/dry/cli/command_registry.rb', line 165

def hidden!(hidden)
  @hidden = hidden
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.

Since:

  • 0.1.0



138
139
140
# File 'lib/dry/cli/command_registry.rb', line 138

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.

Returns:

  • (Boolean)

Since:

  • 0.1.0



171
172
173
# File 'lib/dry/cli/command_registry.rb', line 171

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.

Since:

  • 0.1.0



132
133
134
# File 'lib/dry/cli/command_registry.rb', line 132

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.

Since:

  • 0.1.0



126
127
128
# File 'lib/dry/cli/command_registry.rb', line 126

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.

Since:

  • 0.7.0



144
145
146
147
# File 'lib/dry/cli/command_registry.rb', line 144

def subcommands!(command)
  command_class = command.is_a?(Class) ? command : command.class
  command_class.subcommands = children
end