Class: PulseMeter::CommandAggregator::UDP
- Inherits:
-
Object
- Object
- PulseMeter::CommandAggregator::UDP
- Defined in:
- lib/pulse_meter/command_aggregator/udp.rb
Instance Method Summary collapse
-
#initialize(host, port = nil) ⇒ UDP
constructor
A new instance of UDP.
- #method_missing(*args) ⇒ Object
- #multi ⇒ Object
Constructor Details
#initialize(host, port = nil) ⇒ UDP
Returns a new instance of UDP.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/pulse_meter/command_aggregator/udp.rb', line 8 def initialize(host, port = nil) @servers = if host.is_a?(Array) host else [[host, port]] end raise ArgumentError, "No servers specified" if @servers.empty? @buffer = [] @in_multi = false @sock = UDPSocket.new @sock.fcntl(Fcntl::F_SETFL, @sock.fcntl(Fcntl::F_GETFL) | Fcntl::O_NONBLOCK) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
29 30 31 32 |
# File 'lib/pulse_meter/command_aggregator/udp.rb', line 29 def method_missing(*args) @buffer << args send_buffer unless @in_multi end |
Instance Method Details
#multi ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/pulse_meter/command_aggregator/udp.rb', line 21 def multi @in_multi = true yield ensure @in_multi = false send_buffer end |