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.



1648
1649
1650
# File 'lib/warg.rb', line 1648

def registry
  @registry
end

Class Method Details

.find(argv) ⇒ Object



1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
# File 'lib/warg.rb', line 1667

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



1663
1664
1665
# File 'lib/warg.rb', line 1663

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

.register(klass) ⇒ Object



1653
1654
1655
1656
1657
1658
1659
1660
1661
# File 'lib/warg.rb', line 1653

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