Module: Helpers
- Includes:
- Rack::Utils, Sinatra::ContentFor2, Sinatra::Partials
- Defined in:
- lib/runit-man/helpers.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#even_or_odd_state ⇒ Object
Returns the value of attribute even_or_odd_state.
Instance Method Summary collapse
- #addr ⇒ Object
- #all_files_to_view ⇒ Object
- #even_or_odd ⇒ Object
- #files_to_view ⇒ Object
- #host_name ⇒ Object
- #human_bytes(bytes) ⇒ Object
- #log(s) ⇒ Object
- #log_downloads_link(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
- #t(*args) ⇒ Object
Instance Attribute Details
#even_or_odd_state ⇒ Object
Returns the value of attribute even_or_odd_state.
13 14 15 |
# File 'lib/runit-man/helpers.rb', line 13 def even_or_odd_state @even_or_odd_state end |
Instance Method Details
#addr ⇒ Object
15 16 17 |
# File 'lib/runit-man/helpers.rb', line 15 def addr env.include?('X_REAL_IP') ? env['X_REAL_IP'] : env['REMOTE_ADDR'] end |
#all_files_to_view ⇒ Object
43 44 45 46 47 |
# File 'lib/runit-man/helpers.rb', line 43 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
83 84 85 86 |
# File 'lib/runit-man/helpers.rb', line 83 def even_or_odd self.even_or_odd_state = !even_or_odd_state even_or_odd_state end |
#files_to_view ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/runit-man/helpers.rb', line 35 def files_to_view RunitMan::App.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
23 24 25 |
# File 'lib/runit-man/helpers.rb', line 23 def host_name Utils.host_name end |
#human_bytes(bytes) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/runit-man/helpers.rb', line 93 def human_bytes(bytes) sign = (bytes >= 0) ? '' : '-' suffix = 'B' bytes = bytes.abs.to_f if bytes >= TERABYTE bytes /= TERABYTE suffix = 'TB' elsif bytes >= GIGABYTE bytes /= GIGABYTE suffix = 'GB' elsif bytes >= MEGABYTE bytes /= MEGABYTE suffix = 'MB' elsif bytes >= KILOBYTE bytes /= KILOBYTE suffix = 'KB' end bytes = ((bytes * 100 + 0.5).to_i.to_f / 100) "#{sign}#{bytes}#{t("runit.services.log.#{suffix}")}" end |
#log(s) ⇒ Object
19 20 21 |
# File 'lib/runit-man/helpers.rb', line 19 def log(s) logger.info s end |
#log_downloads_link(name) ⇒ Object
79 80 81 |
# File 'lib/runit-man/helpers.rb', line 79 def log_downloads_link(name) "<a href=\"/#{name}/log-downloads/\">#{h(t('runit.services.log.downloads'))}…</a>" end |
#log_link(name, options = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/runit-man/helpers.rb', line 66 def log_link(name, = {}) count = ([:count] || 100).to_i title = [:title].to_s || count blank = [:blank] || false hint = [:hint].to_s || '' raw = [:raw] || false id = [:id] || false hint = " title=\"#{h(hint)}\"" unless hint.empty? blank = blank ? ' target="_blank"' : '' "<a#{hint}#{blank} href=\"/#{name}/log#{ (count != 100) ? "/#{count}" : '' }#{ id ? "/#{id}" : '' }#{ raw ? '.txt' : '' }#footer\">#{h(title)}</a>" end |
#service_action(name, action, label, enabled = true) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/runit-man/helpers.rb', line 49 def service_action(name, action, label, enabled = true) partial :service_action, :locals => { :name => name, :action => action, :label => label, :enabled => enabled } end |
#service_infos ⇒ Object
31 32 33 |
# File 'lib/runit-man/helpers.rb', line 31 def service_infos ServiceInfo::Base.all end |
#service_signal(name, signal, label) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/runit-man/helpers.rb', line 58 def service_signal(name, signal, label) partial :service_signal, :locals => { :name => name, :signal => signal, :label => label } end |
#stat_subst(s) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/runit-man/helpers.rb', line 117 def stat_subst(s) s.split(/\s/).map do |s| if s =~ /(\w+)/ word = $1 if t("runit.services.table.subst.#{word}") !~ /translation missing/ s.sub(word, t("runit.services.table.subst.#{word}")) else s end else s end end.join(' ') end |