Module: OnStomp
- Defined in:
- lib/onstomp.rb,
lib/onstomp/version.rb
Overview
Primary namespace for the onstomp
gem
Defined Under Namespace
Modules: Components, Connections, Failover, Interfaces, OpenURI Classes: Client, ConnectFailedError, ConnectionTimeoutError, FatalConnectionError, FatalProtocolError, InvalidHeaderCharacterError, InvalidHeaderEscapeSequenceError, MalformedFrameError, MalformedHeaderError, OnStompError, StopReceiver, TransactionError, UnsupportedCommandError, UnsupportedProtocolVersionError
Constant Summary
- ENUMERATOR_KLASS =
Class to use for creating enumerator objects, which depends upon the version of Ruby being used.
(RUBY_VERSION >= '1.9') ? Enumerator : Enumerable::Enumerator
- MAJOR =
Major / API version
1
- MINOR =
Minor / feature version
0
- PATCH =
Patch version
7
- VERSION =
Complete version
"#{MAJOR}.#{MINOR}.#{PATCH}"
Class Method Summary (collapse)
-
+ (Object) connect(uri, options = {})
(also: open)
Creates a new connection and immediately connects it to the broker.
-
+ (Module) constantize(klass)
Converts a string to the Ruby constant it names.
-
+ ({Symbol => Object}) keys_to_sym(hsh)
Duplicates an existing hash while transforming its keys to symbols.
-
+ (Object) next_serial(prefix = nil)
Generates the next serial number in a thread-safe manner.
Class Method Details
+ (Object) connect(uri, options = {}) Also known as: open
Creates a new connection and immediately connects it to the broker.
96 97 98 99 100 |
# File 'lib/onstomp.rb', line 96 def connect(uri, ={}) conx = OnStomp::Client.new(uri, ) conx.connect conx end |
+ (Module) constantize(klass)
Converts a string to the Ruby constant it names. If the klass
parameter
is a kind of Module
, this method will return klass
directly.
140 141 142 143 144 145 146 147 |
# File 'lib/onstomp.rb', line 140 def constantize(klass) return klass if klass.is_a?(Module) || klass.nil? || klass.respond_to?(:new) klass.to_s.split('::').inject(Object) do |const, named| next const if named.empty? const.const_defined?(named) ? const.const_get(named) : const.const_missing(named) end end |
+ ({Symbol => Object}) keys_to_sym(hsh)
Duplicates an existing hash while transforming its keys to symbols.
The keys must implement the to_sym
method, otherwise an exception will
be raised. This method is used internally to convert hashes keyed with
Strings.
114 115 116 117 118 119 |
# File 'lib/onstomp.rb', line 114 def keys_to_sym(hsh) hsh.inject({}) do |new_hash, (k,v)| new_hash[k.to_sym] = v new_hash end end |
+ (Object) next_serial(prefix = nil)
Generates the next serial number in a thread-safe manner. This method merely initializes an instance variable to 0 if it has not been set, then increments this value and returns its string representation.
124 125 126 127 128 129 130 |
# File 'lib/onstomp.rb', line 124 def next_serial(prefix=nil) Thread.exclusive do @next_serial_sequence ||= 0 @next_serial_sequence += 1 @next_serial_sequence.to_s end end |