Class: Proctor::Presenter::Show
- Inherits:
-
Object
- Object
- Proctor::Presenter::Show
- Defined in:
- lib/proctor/presenter/show.rb
Instance Method Summary collapse
- #find_asset(handle) ⇒ Object
-
#initialize(global, options, args) ⇒ Show
constructor
A new instance of Show.
- #show ⇒ Object
- #show_appfile(asset) ⇒ Object
- #show_manager(asset) ⇒ Object
- #show_service(asset) ⇒ Object
- #show_template(asset) ⇒ Object
- #validate_handle(handle) ⇒ Object
- #xhandle(string) ⇒ Object
Constructor Details
#initialize(global, options, args) ⇒ Show
Returns a new instance of Show.
5 6 7 8 9 10 |
# File 'lib/proctor/presenter/show.rb', line 5 def initialize(global, , args) @global = global @options = @args = args validate_handle(args[0]) end |
Instance Method Details
#find_asset(handle) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/proctor/presenter/show.rb', line 22 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
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/proctor/presenter/show.rb', line 40 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
56 57 58 59 |
# File 'lib/proctor/presenter/show.rb', line 56 def show_appfile(asset) puts "# AppFile #{asset}" puts File.read(asset) end |
#show_manager(asset) ⇒ Object
61 62 63 |
# File 'lib/proctor/presenter/show.rb', line 61 def show_manager(asset) puts "# Manager #{asset}" end |
#show_service(asset) ⇒ Object
65 66 67 |
# File 'lib/proctor/presenter/show.rb', line 65 def show_service(asset) puts "# Service #{asset}" end |
#show_template(asset) ⇒ Object
51 52 53 54 |
# File 'lib/proctor/presenter/show.rb', line 51 def show_template(asset) puts "# Template #{asset}" puts File.read(asset) end |
#validate_handle(handle) ⇒ Object
12 13 14 15 16 |
# File 'lib/proctor/presenter/show.rb', line 12 def validate_handle(handle) if handle.length != 3 raise "invalid handle (#{handle}) see 'proctor list for a valid handle'" end end |
#xhandle(string) ⇒ Object
18 19 20 |
# File 'lib/proctor/presenter/show.rb', line 18 def xhandle(string) Digest::MD5.hexdigest(string)[0..2] end |