Class: Ankit::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/ankit/command.rb

Constant Summary collapse

COMMANDS =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime, args = []) ⇒ Command

Returns a new instance of Command.



28
29
30
31
32
33
34
# File 'lib/ankit/command.rb', line 28

def initialize(runtime, args=[])
  @runtime = runtime
  @options = {}
  @args = OptionParser.new do |spec|
    self.class.option_spec.call(spec, @options) if self.class.option_spec
  end.parse(args)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



6
7
8
# File 'lib/ankit/command.rb', line 6

def args
  @args
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/ankit/command.rb', line 6

def options
  @options
end

#runtimeObject (readonly)

Returns the value of attribute runtime.



6
7
8
# File 'lib/ankit/command.rb', line 6

def runtime
  @runtime
end

Class Method Details

.availableObject



10
11
12
# File 'lib/ankit/command.rb', line 10

def self.available
  COMMANDS.push(self)
end

.by_nameObject



18
19
20
21
22
23
# File 'lib/ankit/command.rb', line 18

def self.by_name
  COMMANDS.inject({}) do |a, cls|
    a[cls.command_name] = cls
    a
  end
end

.command_nameObject



14
15
16
# File 'lib/ankit/command.rb', line 14

def self.command_name
  /(.*)\:\:(\w+)Command/.match(self.name).to_a[-1].downcase
end

.define_options(&block) ⇒ Object



25
# File 'lib/ankit/command.rb', line 25

def self.define_options(&block) @option_spec = block end

.option_specObject



26
# File 'lib/ankit/command.rb', line 26

def self.option_spec; @option_spec; end