Module: Ermir::Utils
- Included in:
- Ermir
- Defined in:
- lib/ermir/utils.rb
Class Method Summary collapse
- .error_and_abort!(error_msg, at, other_error_msg = nil) ⇒ Object
- .print_rmi_transport_msg(msg, peeraddr, color = nil) ⇒ Object
- .print_time_msg(msg, color = nil) ⇒ Object
- .stream_header_valid?(stream) ⇒ Boolean
Class Method Details
.error_and_abort!(error_msg, at, other_error_msg = nil) ⇒ Object
9 10 11 12 13 |
# File 'lib/ermir/utils.rb', line 9 def error_and_abort!(error_msg, at, other_error_msg=nil) msg = "Error [#{at}]: #{error_msg[-1].eql?(?.) ? error_msg[...-1] : error_msg}.".red msg += "\n#{' '*4}|_ #{other_error_msg[-1].eql?(?.) ? other_error_msg[...-1] : other_error_msg}." if other_error_msg abort(msg) end |
.print_rmi_transport_msg(msg, peeraddr, color = nil) ⇒ Object
17 18 19 |
# File 'lib/ermir/utils.rb', line 17 def print_rmi_transport_msg(msg, peeraddr, color=nil) puts "[remote-peer-#{[peeraddr[-1], peeraddr[1]].join(':')}] #{msg}".public_send(color&.to_sym||:itself) end |
.print_time_msg(msg, color = nil) ⇒ Object
14 15 16 |
# File 'lib/ermir/utils.rb', line 14 def print_time_msg(msg, color=nil) puts "[#{Time.now.strftime('%I:%M:%S')}] #{msg}".public_send(color&.to_sym||:itself) end |
.stream_header_valid?(stream) ⇒ Boolean
5 6 7 |
# File 'lib/ermir/utils.rb', line 5 def stream_header_valid?(stream) stream[0..3].unpack("L>")[0].eql?(Ermir::TransportConstants::OBJECT_STREAM_MAGIC) end |