Module: Eye::Controller::Helpers
- Included in:
- Eye::Controller
- Defined in:
- lib/eye/controller/helpers.rb
Instance Method Summary collapse
- #all_groups ⇒ Object
- #all_processes ⇒ Object
- #application_by_name(name) ⇒ Object
- #cache_str ⇒ Object
- #find_nearest_process(name, group_name = nil, app_name = nil) ⇒ Object
- #group_by_name(name) ⇒ Object
- #process_by_full_name(name) ⇒ Object
- #process_by_name(name) ⇒ Object
- #save_cache ⇒ Object
- #set_proc_line ⇒ Object
-
#short_tree ⇒ Object
=> {‘group_name’ => {‘process_name’ => ‘pid_file’}}.
Instance Method Details
#all_groups ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/eye/controller/helpers.rb', line 71 def all_groups groups = [] @applications.each do |app| groups += app.groups.to_a end groups end |
#all_processes ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/eye/controller/helpers.rb', line 62 def all_processes processes = [] all_groups.each do |gr| processes += gr.processes.to_a end processes end |
#application_by_name(name) ⇒ Object
57 58 59 60 |
# File 'lib/eye/controller/helpers.rb', line 57 def application_by_name(name) name = name.to_s @applications.detect { |c| c.name == name } end |
#cache_str ⇒ Object
18 19 20 |
# File 'lib/eye/controller/helpers.rb', line 18 def cache_str all_processes.map { |p| "#{p.full_name}=#{p.state}" } * "\n" end |
#find_nearest_process(name, group_name = nil, app_name = nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/eye/controller/helpers.rb', line 32 def find_nearest_process(name, group_name = nil, app_name = nil) return process_by_full_name(name) if name.include?(':') if app_name app = application_by_name(app_name) app.groups.each do |gr| p = gr.processes.detect { |c| c.name == name } return p if p end end if group_name gr = group_by_name(group_name) p = gr.processes.detect { |c| c.name == name } return p if p end process_by_name(name) end |
#group_by_name(name) ⇒ Object
52 53 54 55 |
# File 'lib/eye/controller/helpers.rb', line 52 def group_by_name(name) name = name.to_s all_groups.detect { |c| c.name == name } end |
#process_by_full_name(name) ⇒ Object
27 28 29 30 |
# File 'lib/eye/controller/helpers.rb', line 27 def process_by_full_name(name) name = name.to_s all_processes.detect { |c| c.full_name == name } end |
#process_by_name(name) ⇒ Object
22 23 24 25 |
# File 'lib/eye/controller/helpers.rb', line 22 def process_by_name(name) name = name.to_s all_processes.detect { |c| c.name == name } end |
#save_cache ⇒ Object
12 13 14 15 16 |
# File 'lib/eye/controller/helpers.rb', line 12 def save_cache File.open(Eye::Local.cache_path, 'w') { |f| f.write(cache_str) } rescue => ex log_ex(ex) end |
#set_proc_line ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/eye/controller/helpers.rb', line 3 def set_proc_line str = Eye::PROCLINE str = 'l' + str if Eye::Local.local_runner str += " [#{@applications.map(&:name) * ', '}]" if @applications.present? str += " (v #{ENV['EYE_V']})" if ENV['EYE_V'] str += " (in #{Eye::Local.home})" $0 = str end |
#short_tree ⇒ Object
=> {‘group_name’ => {‘process_name’ => ‘pid_file’}}
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/eye/controller/helpers.rb', line 81 def short_tree res = {} @applications.each do |app| res2 = {} app.groups.each do |group| res3 = {} group.processes.each do |process| res3[process.name] = process[:pid_file_ex] end res2[group.name] = res3 end res[app.name] = res2 end res end |