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



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

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



107
108
109
# File 'lib/dry/cli/command_registry.rb', line 107

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



91
92
93
# File 'lib/dry/cli/command_registry.rb', line 91

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



103
104
105
# File 'lib/dry/cli/command_registry.rb', line 103

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



87
88
89
# File 'lib/dry/cli/command_registry.rb', line 87

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



99
100
101
# File 'lib/dry/cli/command_registry.rb', line 99

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



95
96
97
# File 'lib/dry/cli/command_registry.rb', line 95

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



83
84
85
# File 'lib/dry/cli/command_registry.rb', line 83

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



149
150
151
# File 'lib/dry/cli/command_registry.rb', line 149

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



155
156
157
158
159
# File 'lib/dry/cli/command_registry.rb', line 155

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



175
176
177
# File 'lib/dry/cli/command_registry.rb', line 175

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



163
164
165
# File 'lib/dry/cli/command_registry.rb', line 163

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



136
137
138
# File 'lib/dry/cli/command_registry.rb', line 136

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



169
170
171
# File 'lib/dry/cli/command_registry.rb', line 169

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



130
131
132
# File 'lib/dry/cli/command_registry.rb', line 130

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



124
125
126
# File 'lib/dry/cli/command_registry.rb', line 124

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



142
143
144
145
# File 'lib/dry/cli/command_registry.rb', line 142

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