Module: Helpers
- Includes:
- Rack::Utils, Sinatra::ContentFor, Sinatra::Partials
- Defined in:
- lib/runit-man/helpers.rb
Instance Attribute Summary collapse
-
#even_or_odd_state ⇒ Object
Returns the value of attribute even_or_odd_state.
Instance Method Summary collapse
- #all_files_to_view ⇒ Object
- #even_or_odd ⇒ Object
- #files_to_view ⇒ Object
- #host_name ⇒ Object
- #log_link(name, options = {}) ⇒ Object
- #service_action(name, action, label, enabled = true) ⇒ Object
- #service_infos ⇒ Object
- #service_signal(name, signal, label) ⇒ Object
- #stat_subst(s) ⇒ Object
Instance Attribute Details
#even_or_odd_state ⇒ Object
Returns the value of attribute even_or_odd_state.
12 13 14 |
# File 'lib/runit-man/helpers.rb', line 12 def even_or_odd_state @even_or_odd_state end |
Instance Method Details
#all_files_to_view ⇒ Object
37 38 39 40 41 |
# File 'lib/runit-man/helpers.rb', line 37 def all_files_to_view (files_to_view + service_infos.map do |service| service.files_to_view end.flatten).uniq.sort end |
#even_or_odd ⇒ Object
71 72 73 74 |
# File 'lib/runit-man/helpers.rb', line 71 def even_or_odd self.even_or_odd_state = !even_or_odd_state even_or_odd_state end |
#files_to_view ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/runit-man/helpers.rb', line 29 def files_to_view RunitMan.files_to_view.map do |f| File.symlink?(f) ? File.(File.readlink(f), File.dirname(f)) : f end.select do |f| File.readable?(f) end.uniq.sort end |
#host_name ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/runit-man/helpers.rb', line 14 def host_name unless @host_name begin @host_name = Socket.gethostbyname(Socket.gethostname).first rescue @host_name = Socket.gethostname end end @host_name end |
#log_link(name, options = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/runit-man/helpers.rb', line 60 def log_link(name, = {}) count = ([:count] || 100).to_i title = [:title].to_s || count blank = [:blank] || false hint = [:hint].to_s || '' raw = [:raw] || false hint = " title=\"#{h(hint)}\"" unless hint.empty? blank = blank ? ' target="_blank"' : '' "<a#{hint}#{blank} href=\"/#{h(name)}/log#{ (count != 100) ? "/#{count}" : '' }#{ raw ? '.txt' : '' }#footer\">#{h(title)}</a>" end |
#service_action(name, action, label, enabled = true) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/runit-man/helpers.rb', line 43 def service_action(name, action, label, enabled = true) partial :service_action, :locals => { :name => name, :action => action, :label => label, :enabled => enabled } end |
#service_infos ⇒ Object
25 26 27 |
# File 'lib/runit-man/helpers.rb', line 25 def service_infos ServiceInfo.all end |
#service_signal(name, signal, label) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/runit-man/helpers.rb', line 52 def service_signal(name, signal, label) partial :service_signal, :locals => { :name => name, :signal => signal, :label => label } end |
#stat_subst(s) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/runit-man/helpers.rb', line 76 def stat_subst(s) s.split(/\s/).map do |s| if s =~ /(\w+)/ && t.runit.services.table.subst[$1].translated? s.sub(/\w+/, t.runit.services.table.subst[$1].to_s) else s end end.join(' ') end |