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

#even_or_oddObject



48
49
50
51
# File 'lib/runit-man/helpers.rb', line 48

def even_or_odd
  self.even_or_odd_state = !even_or_odd_state
  even_or_odd_state
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


37
38
39
40
41
42
43
44
45
46
# File 'lib/runit-man/helpers.rb', line 37

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) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/runit-man/helpers.rb', line 29

def service_action(name, action, label)
  partial :service_action, :locals => {
    :name   => name,
    :action => action,
    :label  => label
  }
end

#service_infosObject



25
26
27
# File 'lib/runit-man/helpers.rb', line 25

def service_infos
  ServiceInfo.all
end

#stat_subst(s) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/runit-man/helpers.rb', line 53

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