module Invoker::IPC

Constants

INITIAL_PACKET_SIZE

Public Class Methods

camelize(term) click to toggle source

Taken from Rails without inflection support

# File lib/invoker/ipc.rb, line 28
def self.camelize(term)
  string = term.to_s
  string = string.sub(/^[a-z\d]*/) { $&.capitalize }
  string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
  string.gsub!('/', '::')
  string
end
message_from_io(io) click to toggle source
# File lib/invoker/ipc.rb, line 18
def self.message_from_io(io)
  json_size = io.read(INITIAL_PACKET_SIZE)
  json_string = io.read(json_size.to_i)
  ruby_object_hash = JSON.parse(json_string)
  command_name = camelize(ruby_object_hash['type'])
  command_klass = Invoker::IPC::Message.const_get(command_name)
  command_klass.new(ruby_object_hash)
end
underscore(term) click to toggle source
# File lib/invoker/ipc.rb, line 36
def self.underscore(term)
  word = term.to_s.gsub('::', '/')
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  word.tr!("-", "_")
  word.downcase!
  word
end