Module: RabbitMQ::Util Private
- Defined in:
- lib/rabbitmq/util.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Helper functions for this library.
Class Method Summary collapse
- .connection_info(url = nil, **overrides) ⇒ Object private
- .const_name(lowercase_name) ⇒ Object private
- .error_check(action, status) ⇒ Object private
- .mem_ptr(size, count: 1, clear: true, release: true) ⇒ Object private
- .null_check(action, obj) ⇒ Object private
- .strdup_ptr(str, **kwargs) ⇒ Object private
Class Method Details
.connection_info(url = nil, **overrides) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rabbitmq/util.rb', line 36 def connection_info(url=nil, **overrides) info = FFI::ConnectionInfo.new FFI.amqp_default_connection_info(info) result = info.to_h if url url_ptr = Util.strdup_ptr(url) Util.error_check :"parsing connection URL", FFI.amqp_parse_url(url_ptr, info) # We must copy ConnectionInfo before the url_ptr is freed. result.merge!(info.to_h) url_ptr.free end result.merge(overrides) end |
.const_name(lowercase_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/rabbitmq/util.rb', line 9 def const_name(lowercase_name) lowercase_name.to_s.gsub(/((?:\A\w)|(?:_\w))/) { |x| x[-1].upcase } end |
.error_check(action, status) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 16 |
# File 'lib/rabbitmq/util.rb', line 13 def error_check(action, status) return if status == :ok raise RabbitMQ::FFI::Error.lookup(status), "while #{action}" end |
.mem_ptr(size, count: 1, clear: true, release: true) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 26 27 |
# File 'lib/rabbitmq/util.rb', line 23 def mem_ptr(size, count: 1, clear: true, release: true) ptr = ::FFI::MemoryPointer.new(size, count, clear) ptr.autorelease = false unless release ptr end |
.null_check(action, obj) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
18 19 20 21 |
# File 'lib/rabbitmq/util.rb', line 18 def null_check(action, obj) return unless obj.nil? raise RabbitMQ::FFI::Error, "while #{action} - got unexpected null" end |
.strdup_ptr(str, **kwargs) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 30 31 32 33 34 |
# File 'lib/rabbitmq/util.rb', line 29 def strdup_ptr(str, **kwargs) str = str + "\x00" ptr = mem_ptr(str.bytesize, **kwargs) ptr.write_string(str) ptr end |