Class: Ruberl::Base
- Inherits:
-
Object
- Object
- Ruberl::Base
- Defined in:
- lib/ruberl/base.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(host = "localhost", port = 7050) ⇒ Base
constructor
A new instance of Base.
- #messenger_cast!(msg = "force_reconfig") ⇒ Object
- #messenger_send!(msg = "get_current_load cpu") ⇒ Object
- #with_socket(&block) ⇒ Object
Constructor Details
#initialize(host = "localhost", port = 7050) ⇒ Base
Returns a new instance of Base.
4 5 6 7 |
# File 'lib/ruberl/base.rb', line 4 def initialize(host="localhost", port=7050) @host = host @port = port end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
3 4 5 |
# File 'lib/ruberl/base.rb', line 3 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
3 4 5 |
# File 'lib/ruberl/base.rb', line 3 def port @port end |
Instance Method Details
#messenger_cast!(msg = "force_reconfig") ⇒ Object
24 25 26 27 28 |
# File 'lib/ruberl/base.rb', line 24 def messenger_cast!(msg="force_reconfig") with_socket do |sock| sock.send(msg, 0) end end |
#messenger_send!(msg = "get_current_load cpu") ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/ruberl/base.rb', line 17 def messenger_send!(msg="get_current_load cpu") with_socket do |sock| sock.send(msg, 0) @str = sock.recv(2000) end @str end |
#with_socket(&block) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/ruberl/base.rb', line 8 def with_socket(&block) begin socket = TCPSocket.open(@host, @port) out = yield(socket) socket.close out rescue Exception => e end end |