Module: Refinery::Utilities
- Defined in:
- lib/refinery/utilities.rb
Overview
Utilities that can be mixed into a class
Instance Method Summary collapse
-
#camelize(word, first_letter_in_uppercase = true) ⇒ Object
Camelize the given word.
-
#decode_message(message_body) ⇒ Object
Decode the message_body from Base 64 and then parse from JSON.
-
#encode_message(message_data) ⇒ Object
Convert the given message_data object to JSON and then Base 64 encode it.
-
#host_info ⇒ Object
Get a Hash of useful host information that can be sent with messages to the monitoring system.
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 () JSON.parse(Base64.decode64()) 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 () Base64.encode64(.to_json) end |
#host_info ⇒ Object
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 |