Class: Mooncell::CLI::Commands::Registry::Node Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mooncell/cli/commands/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.

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, command = nil, app_only: false) ⇒ 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



56
57
58
59
60
61
# File 'lib/mooncell/cli/commands/registry.rb', line 56

def initialize(name = nil, command = nil, app_only: false)
  @name = name
  @command = command
  @children = {}
  @app_only = app_only
end

Instance Attribute Details

#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



52
53
54
# File 'lib/mooncell/cli/commands/registry.rb', line 52

def command
  @command
end

#nameObject (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



52
53
54
# File 'lib/mooncell/cli/commands/registry.rb', line 52

def name
  @name
end

Instance Method Details

#add(name, command = nil, aliases: [], app_only: false, &block) ⇒ 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



80
81
82
83
84
# File 'lib/mooncell/cli/commands/registry.rb', line 80

def add(name, command = nil, aliases: [], app_only: false, &block)
  node = Node.new(name, command || block, app_only: app_only)
  @children[name] = node
  aliases.each { |token| @children[token] = node }
end

#app_only?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 is only for application.

Returns:

  • (Boolean)

    is only for application

Since:

  • 0.1.0



67
68
69
# File 'lib/mooncell/cli/commands/registry.rb', line 67

def app_only?
  @app_only == true
end

#call(*args) ⇒ 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



94
95
96
97
98
99
100
# File 'lib/mooncell/cli/commands/registry.rb', line 94

def call(*args)
  return if app_only? && !Commands.app_initialized?
  return if command.nil?
  return command.call(*args) if command.is_a?(Proc)

  command.new.call(*args)
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 is the end of command.

Returns:

  • (Boolean)

    is the end of command

Since:

  • 0.1.0



74
75
76
# File 'lib/mooncell/cli/commands/registry.rb', line 74

def leaf?
  @children.empty?
end

#lookup(name) ⇒ 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



88
89
90
# File 'lib/mooncell/cli/commands/registry.rb', line 88

def lookup(name)
  @children[name]
end