Class: Bow::Command

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, argv = []) ⇒ Command

Returns a new instance of Command.



35
36
37
38
# File 'lib/bow/command.rb', line 35

def initialize(app = nil, argv = [])
  @app = app
  @argv = argv
end

Class Attribute Details

.allObject (readonly)

Returns the value of attribute all.



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

def all
  @all
end

.namesObject (readonly)

Returns the value of attribute names.



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

def names
  @names
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



33
34
35
# File 'lib/bow/command.rb', line 33

def app
  @app
end

Class Method Details

.command_nameObject



15
16
17
18
19
20
21
22
23
# File 'lib/bow/command.rb', line 15

def command_name
  @command_name ||= name.to_s
                        .split('::')
                        .last
                        .split(/([A-Z]{1}[^A-Z]*)/)
                        .reject(&:empty?)
                        .join('_')
                        .downcase
end

.find(name) ⇒ Object



25
26
27
28
# File 'lib/bow/command.rb', line 25

def find(name)
  index = @names.index name.to_s
  @all[index] if index
end

.inherited(command_class) ⇒ Object



8
9
10
11
12
13
# File 'lib/bow/command.rb', line 8

def inherited(command_class)
  @all ||= []
  @names ||= []
  @all << command_class
  @names << command_class.command_name
end

Instance Method Details

#command_nameObject



48
49
50
# File 'lib/bow/command.rb', line 48

def command_name
  self.class.command_name
end

#descriptionObject



40
41
42
# File 'lib/bow/command.rb', line 40

def description
  @description ||= "Command #{command_name} description"
end

#targetsObject



52
53
54
55
56
# File 'lib/bow/command.rb', line 52

def targets
  user = app.options[:user]
  group = app.options[:group]
  app.targets(user).hosts(group)
end

#usageObject



44
45
46
# File 'lib/bow/command.rb', line 44

def usage
  @usage ||= "bow #{command_name} [args] [options]"
end