Module: Helpers

Includes:
Rack::Utils, Sinatra::ContentFor, Sinatra::Partials
Defined in:
lib/runit-man/helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#even_or_odd_stateObject

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_viewObject



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_oddObject



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_viewObject



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.expand_path(File.readlink(f), File.dirname(f)) : f
  end.select do |f|
    File.readable?(f)
  end.uniq.sort
end

#host_nameObject



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


60
61
62
63
64
65
66
67
68
69
# File 'lib/runit-man/helpers.rb', line 60

def log_link(name, options = {})
  count = (options[:count] || 100).to_i
  title = options[:title].to_s || count
  blank = options[:blank] || false
  hint  = options[:hint].to_s  || ''
  raw   = options[: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_infosObject



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