Module: Refinery::Utilities

Included in:
Daemon, EventPublisher, Heartbeat, Monitor, Server, Worker
Defined in:
lib/refinery/utilities.rb

Overview

Utilities that can be mixed into a class

Instance Method Summary collapse

Instance Method Details

#camelize(word, first_letter_in_uppercase = true) ⇒ Object

Camelize the given word.



5
6
7
8
9
10
11
# File 'lib/refinery/utilities.rb', line 5

def camelize(word, first_letter_in_uppercase = true)
  if first_letter_in_uppercase
    word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  else
    word.first.downcase + camelize(word)[1..-1]
  end
end

#decode_message(message_body) ⇒ Object

Decode the message_body from Base 64 and then parse from JSON.



14
15
16
# File 'lib/refinery/utilities.rb', line 14

def decode_message(message_body)
  JSON.parse(Base64.decode64(message_body))
end

#encode_message(message_data) ⇒ Object

Convert the given message_data object to JSON and then Base 64 encode it



20
21
22
# File 'lib/refinery/utilities.rb', line 20

def encode_message(message_data)
  Base64.encode64(message_data.to_json)
end

#host_infoObject

Get a Hash of useful host information that can be sent with messages to the monitoring system.



26
27
28
29
30
31
# File 'lib/refinery/utilities.rb', line 26

def host_info
  {
    'hostname' => Socket.gethostname,
    'pid' => $$
  }
end