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, Step

Class Attribute Summary collapse

Attributes included from BehaviorWithoutRegistration

#argv, #context, #hosts, #parser, #playlist

Class Method Summary collapse

Methods included from BehaviorWithoutRegistration

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

Class Attribute Details

.registryObject (readonly)

Returns the value of attribute registry.



1738
1739
1740
# File 'lib/warg.rb', line 1738

def registry
  @registry
end

Class Method Details

.find(argv) ⇒ Object



1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
# File 'lib/warg.rb', line 1757

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



1753
1754
1755
# File 'lib/warg.rb', line 1753

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

.register(klass) ⇒ Object



1743
1744
1745
1746
1747
1748
1749
1750
1751
# File 'lib/warg.rb', line 1743

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