Class: Warg::Command

Inherits:
Object
  • Object
show all
Includes:
BehaviorWithoutRegistration
Defined in:
lib/warg.rb

Defined Under Namespace

Modules: Behavior, BehaviorWithoutRegistration, Chaining, CommandMissingHook, Naming Classes: Name

Class Attribute Summary collapse

Attributes included from BehaviorWithoutRegistration

#argv, #context, #hosts, #operations, #parser, #steps

Class Method Summary collapse

Methods included from BehaviorWithoutRegistration

#SGR, #call, #chain, #command_name, included, #initialize, #name, #on_failure, #run, #setup, #|

Class Attribute Details

.registryObject (readonly)

Returns the value of attribute registry


1779
1780
1781
# File 'lib/warg.rb', line 1779

def registry
  @registry
end

Class Method Details

.find(argv) ⇒ Object


1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
# File 'lib/warg.rb', line 1798

def self.find(argv)
  klass = nil

  argv.each do |arg|
    if @registry.key?(arg)
      klass = @registry.fetch(arg)
    end
  end

  klass
end

.inherited(klass) ⇒ Object


1794
1795
1796
# File 'lib/warg.rb', line 1794

def self.inherited(klass)
  register(klass)
end

.register(klass) ⇒ Object


1784
1785
1786
1787
1788
1789
1790
1791
1792
# File 'lib/warg.rb', line 1784

def self.register(klass)
  if Warg::Command.registry.key?(klass.registry_name)
    # TODO: include debug information in the warning
    $stderr.puts "[WARN] command with the name `#{klass.command_name}' already exists " \
      "and is being replaced"
  end

  Warg::Command.registry[klass.registry_name] = klass
end