Class: Lwes::Emitter
- Inherits:
-
Object
- Object
- Lwes::Emitter
- Defined in:
- lib/lwes/emitter.rb
Overview
Emit LWES events to a UDP endpoint
Constant Summary collapse
- DEFAULT_SOCIKET_OPTIONS =
{ :address_family => Socket::AF_INET, :host => "127.0.0.1", :port => 12345 }
Instance Attribute Summary collapse
-
#socket ⇒ Object
Returns the value of attribute socket.
-
#socket_options ⇒ Object
Returns the value of attribute socket_options.
Instance Method Summary collapse
-
#emit(event) ⇒ Number
Emits specified event.
-
#initialize(options = {}) ⇒ Emitter
constructor
Creates a new Emitter.
Constructor Details
#initialize(options = {}) ⇒ Emitter
Creates a new Lwes::Emitter.
19 20 21 22 23 |
# File 'lib/lwes/emitter.rb', line 19 def initialize(={}) self. = DEFAULT_SOCIKET_OPTIONS.merge() self.socket = UDPSocket.new(@socket_options[:address_family]) socket.connect(@socket_options[:host], @socket_options[:port]) end |
Instance Attribute Details
#socket ⇒ Object
Returns the value of attribute socket.
12 13 14 |
# File 'lib/lwes/emitter.rb', line 12 def socket @socket end |
#socket_options ⇒ Object
Returns the value of attribute socket_options.
12 13 14 |
# File 'lib/lwes/emitter.rb', line 12 def @socket_options end |
Instance Method Details
#emit(event) ⇒ Number
Emits specified event
28 29 30 31 32 33 |
# File 'lib/lwes/emitter.rb', line 28 def emit(event) buffer = StringIO.new event.write(buffer) buffer.rewind socket.write(buffer.read) end |