Class: Shatter::Pid

Inherits:
Struct
  • Object
show all
Defined in:
lib/shatter/pid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#boxObject

Returns the value of attribute box

Returns:

  • (Object)

    the current value of box


4
5
6
# File 'lib/shatter/pid.rb', line 4

def box
  @box
end

#hostObject

Returns the value of attribute host

Returns:

  • (Object)

    the current value of host


4
5
6
# File 'lib/shatter/pid.rb', line 4

def host
  @host
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name


4
5
6
# File 'lib/shatter/pid.rb', line 4

def name
  @name
end

#pidObject

Returns the value of attribute pid

Returns:

  • (Object)

    the current value of pid


4
5
6
# File 'lib/shatter/pid.rb', line 4

def pid
  @pid
end

#portObject

Returns the value of attribute port

Returns:

  • (Object)

    the current value of port


4
5
6
# File 'lib/shatter/pid.rb', line 4

def port
  @port
end

Instance Method Details

#inspectObject Also known as: to_s

Public: Represent the Pid as a String.

Returns a String.


23
24
25
# File 'lib/shatter/pid.rb', line 23

def inspect
  "<#{pid} #{host}:#{port}#{" (#{name})" unless name.empty?}>"
end

#pass(*messages) ⇒ Object

Public: Open a socket to a given Controller and send any number of messages to it.

messages - Any number of arguments which will constitute a message to be

sent to the Controller.

Returns nothing.


12
13
14
15
16
17
18
# File 'lib/shatter/pid.rb', line 12

def pass(*messages)
  socket  = TCPSocket.new(host, port)
  nonce   = RbNaCl::Random.random_bytes(RbNaCl::SecretBox::NONCEBYTES)
  message = box.encrypt(nonce, Marshal.dump(messages))
  socket.send(Marshal.dump([nonce, message]), 0)
  socket.close
end