Class: Proctor::Command::AssetShowCmd
- Inherits:
-
Object
- Object
- Proctor::Command::AssetShowCmd
show all
- Includes:
- Helpers::Command
- Defined in:
- lib/proctor/command/asset_show_cmd.rb
Instance Method Summary
collapse
#check_number_of_args, #options_msg
Constructor Details
#initialize(global, options, args) ⇒ AssetShowCmd
Returns a new instance of AssetShowCmd.
9
10
11
12
13
14
15
|
# File 'lib/proctor/command/asset_show_cmd.rb', line 9
def initialize(global, options, args)
@global = global
@options = options
@args = args
check_number_of_args(args, 1, 'show HANDLE')
validate_handle(args[0])
end
|
Instance Method Details
#find_asset(handle) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/proctor/command/asset_show_cmd.rb', line 27
def find_asset(handle)
result = @options[:templates].values.find {|x| xhandle(x) == handle}
return ['template', result] unless result.nil?
result = AppConfig.app_files(@global).find {|x| xhandle(x) == handle}
return ['appfile', result] unless result.nil?
result = @options[:app_config]['managers'].keys.find {|x| xhandle(x) == handle}
return ['manager', result] unless result.nil?
result = @options[:app_config]['services'].keys.find {|x| xhandle(x) == handle}
return ['service', result] unless result.nil?
raise "unknown handle (#{handle}) see 'proctor list' for a valid handle"
end
|
#show ⇒ Object
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/proctor/command/asset_show_cmd.rb', line 45
def show
type, asset = find_asset(@args[0])
case type
when "template" then show_template(asset)
when "appfile" then show_appfile(asset)
when "manager" then show_manager(asset)
when "service" then show_service(asset)
end
end
|
#show_appfile(asset) ⇒ Object
61
62
63
64
|
# File 'lib/proctor/command/asset_show_cmd.rb', line 61
def show_appfile(asset)
puts "# AppFile #{asset}"
puts File.read(asset)
end
|
#show_manager(asset) ⇒ Object
66
67
68
|
# File 'lib/proctor/command/asset_show_cmd.rb', line 66
def show_manager(asset)
puts "# Manager #{asset}"
end
|
#show_service(asset) ⇒ Object
70
71
72
|
# File 'lib/proctor/command/asset_show_cmd.rb', line 70
def show_service(asset)
puts "# Service #{asset}"
end
|
#show_template(asset) ⇒ Object
56
57
58
59
|
# File 'lib/proctor/command/asset_show_cmd.rb', line 56
def show_template(asset)
puts "# Template #{asset}"
puts File.read(asset)
end
|
#validate_handle(handle) ⇒ Object
17
18
19
20
21
|
# File 'lib/proctor/command/asset_show_cmd.rb', line 17
def validate_handle(handle)
if handle.length != 3
raise "invalid handle (#{handle}) see 'proctor list for a valid handle'"
end
end
|
#xhandle(string) ⇒ Object
23
24
25
|
# File 'lib/proctor/command/asset_show_cmd.rb', line 23
def xhandle(string)
Digest::MD5.hexdigest(string)[0..2]
end
|