Module: Invoker::IPC

Defined in:
lib/invoker/ipc.rb,
lib/invoker/ipc/server.rb,
lib/invoker/ipc/message.rb,
lib/invoker/ipc/add_command.rb,
lib/invoker/ipc/unix_client.rb,
lib/invoker/ipc/base_command.rb,
lib/invoker/ipc/list_command.rb,
lib/invoker/ipc/ping_command.rb,
lib/invoker/ipc/tail_command.rb,
lib/invoker/ipc/client_handler.rb,
lib/invoker/ipc/reload_command.rb,
lib/invoker/ipc/remove_command.rb,
lib/invoker/ipc/add_http_command.rb,
lib/invoker/ipc/dns_check_command.rb,
lib/invoker/ipc/message/list_response.rb,
lib/invoker/ipc/message/tail_response.rb

Defined Under Namespace

Modules: Message Classes: AddCommand, AddHttpCommand, BaseCommand, ClientHandler, DnsCheckCommand, ListCommand, PingCommand, ReloadCommand, RemoveCommand, Server, TailCommand, UnixClient

Constant Summary collapse

INITIAL_PACKET_SIZE =
9

Class Method Summary collapse

Class Method Details

.camelize(term) ⇒ Object

Taken from Rails without inflection support



28
29
30
31
32
33
34
# 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) ⇒ Object



18
19
20
21
22
23
24
25
# 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) ⇒ Object



36
37
38
39
40
41
42
43
# 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