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
- #all_files_to_view ⇒ Object
- #even_or_odd ⇒ Object
- #files_to_view ⇒ Object
- #host_name ⇒ Object
- #human_bytes(bytes) ⇒ 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
#all_files_to_view ⇒ Object
35 36 37 38 39 |
# File 'lib/runit-man/helpers.rb', line 35 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
73 74 75 76 |
# File 'lib/runit-man/helpers.rb', line 73 def even_or_odd self.even_or_odd_state = !even_or_odd_state even_or_odd_state end |
#files_to_view ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/runit-man/helpers.rb', line 27 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
15 16 17 |
# File 'lib/runit-man/helpers.rb', line 15 def host_name Utils.host_name end |
#human_bytes(bytes) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/runit-man/helpers.rb', line 82 def human_bytes(bytes) sign = (bytes >= 0) ? '' : '-' suffix = 'b' bytes = bytes.abs.to_f if 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_downloads_link(name) ⇒ Object
69 70 71 |
# File 'lib/runit-man/helpers.rb', line 69 def log_downloads_link(name) "<a target=\"_blank\" href=\"/#{name}/log-downloads\/\">#{h(t('runit.services.log.downloads'))}…</a>" end |
#log_link(name, options = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/runit-man/helpers.rb', line 58 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=\"/#{name}/log#{ (count != 100) ? "/#{count}" : '' }#{ raw ? '.txt' : '' }#footer\">#{h(title)}</a>" end |
#service_action(name, action, label, enabled = true) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/runit-man/helpers.rb', line 41 def service_action(name, action, label, enabled = true) partial :service_action, :locals => { :name => name, :action => action, :label => label, :enabled => enabled } end |
#service_infos ⇒ Object
23 24 25 |
# File 'lib/runit-man/helpers.rb', line 23 def service_infos ServiceInfo.all end |
#service_signal(name, signal, label) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/runit-man/helpers.rb', line 50 def service_signal(name, signal, label) partial :service_signal, :locals => { :name => name, :signal => signal, :label => label } end |
#stat_subst(s) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/runit-man/helpers.rb', line 100 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 |