Class: Management::Command
- Inherits:
-
Object
- Object
- Management::Command
show all
- Defined in:
- lib/management/command.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.all ⇒ Object
10
11
12
|
# File 'lib/management/command.rb', line 10
def all
@all ||= []
end
|
.command_name ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/management/command.rb', line 35
def command_name
self.name.split('::').last.
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
tr("_", "-").
downcase
end
|
.help_string ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/management/command.rb', line 18
def help_string
params = instance_method(:call).parameters
output = sprintf("%20s ", command_name)
args = []
params.each do |req, name|
name = "<#{name.to_s.sub('_name', '')}>"
if req == :opt
name = "[#{name}]"
end
args << name
end
return output + args.join(' ')
end
|
.inherited(subclass) ⇒ Object
14
15
16
|
# File 'lib/management/command.rb', line 14
def inherited(subclass)
all << subclass
end
|
Instance Method Details
#cloud ⇒ Object
68
69
70
|
# File 'lib/management/command.rb', line 68
def cloud
@cloud ||= Fog::Compute.new(config[:cloud])
end
|
#config ⇒ Object
64
65
66
|
# File 'lib/management/command.rb', line 64
def config
@config ||= symbolize_keys!(raw_yaml)
end
|
#get_env(name) ⇒ Object
46
47
48
49
|
# File 'lib/management/command.rb', line 46
def get_env(name)
return nil if name.nil?
config[:envs].include?(name) and name or invalid_selection "Invalid environment: #{name}", config[:envs]
end
|
#get_script(name) ⇒ Object
55
56
57
|
# File 'lib/management/command.rb', line 55
def get_script(name)
config[:scripts][name.to_sym] or invalid_selection "Invalid script: #{name}", config[:scripts].map(&:first)
end
|
#get_server(name) ⇒ Object
59
60
61
62
|
# File 'lib/management/command.rb', line 59
def get_server(name)
servers = cloud.servers
servers.find{|server| server.name == name} or invalid_selection "Invalid server: #{name}", servers.map(&:name)
end
|
#get_type(name) ⇒ Object
51
52
53
|
# File 'lib/management/command.rb', line 51
def get_type(name)
config[:types][name.to_sym] or invalid_selection "Invalid type: #{name}", config[:types].map(&:first)
end
|