Top Level Namespace

Defined Under Namespace

Classes: Alarm, Perhoa, SocketListener

Constant Summary collapse

SOCKET_FILE =
"/tmp/perhoa.sock"

Instance Method Summary collapse

Instance Method Details

#already_running?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/helper.rb', line 18

def already_running? 
  File.socket?(SOCKET_FILE)
end

#asset(file) ⇒ Object



3
4
5
# File 'lib/helper.rb', line 3

def asset file
  File.join(File.dirname(__FILE__), '../assets/' + file)
end

#daemonObject



37
38
39
40
# File 'lib/helper.rb', line 37

def daemon
  puts "Running as daemon"
  Process.daemon(true, false) 
end

#quitObject



32
33
34
35
# File 'lib/helper.rb', line 32

def quit 
  puts 'Terminated via socket'
  exit 
end

#read_configObject



28
29
30
# File 'lib/helper.rb', line 28

def read_config
  Alarm.new($config[:alarm]) if $config[:alarm]
end

#send_messageObject



22
23
24
25
26
# File 'lib/helper.rb', line 22

def send_message
  client = UNIXSocket.open SOCKET_FILE
  client.print ARGV.to_yaml
  client.close
end

#symbolise(hash) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/helper.rb', line 7

def symbolise hash
  hash.keys.each do |key|
    hash[key.to_sym] = hash[key]
    hash.delete(key)
    if hash[key.to_sym].is_a?(Hash)
      symbolise hash[key.to_sym]
    end
  end
  return hash
end