Class: OnStomp::Failover::URI::FAILOVER
- Inherits:
-
Components::URI::STOMP
- Object
- URI::Generic
- Components::URI::STOMP
- OnStomp::Failover::URI::FAILOVER
- Defined in:
- lib/onstomp/failover/uri.rb
Overview
A URI class for representing URIs with a 'failover' scheme. We don't need to worry about hooking into Ruby's URI parsing jazz since we have full control over when failover URIs will be created.
Constant Summary
- FAILOVER_REG =
Matches a failover URI string, grouping the list of real URIs and any query parameters for the failover URI.
/^failover:(?:\/\/)?\(?([^\)]+)\)?(?:\?(.*))?/
Constants inherited from Components::URI::STOMP
Instance Attribute Summary (collapse)
-
- (Object) failover_uris
readonly
Returns the value of attribute failover_uris.
Class Method Summary (collapse)
-
+ (Object) parse(uri_str)
Parses a failover URI string or an array of URIs into a FAILOVER object.
Instance Method Summary (collapse)
-
- (FAILOVER) initialize(uris, query)
constructor
A new instance of FAILOVER.
-
- (String) to_s
Converts a failover URI into a string.
Methods inherited from Components::URI::STOMP
Constructor Details
- (FAILOVER) initialize(uris, query)
A new instance of FAILOVER
14 15 16 17 |
# File 'lib/onstomp/failover/uri.rb', line 14 def initialize uris, query @failover_uris = uris super 'failover', nil, nil, nil, nil, '', "(#{uris.join(',')})", query, nil end |
Instance Attribute Details
- (Object) failover_uris (readonly)
Returns the value of attribute failover_uris
13 14 15 |
# File 'lib/onstomp/failover/uri.rb', line 13 def failover_uris @failover_uris end |
Class Method Details
+ (FAILOVER) parse(str) + (FAILOVER) parse(uri_arr)
If you are using the open-uri
extension with failover
, you
MUST use the failover:(uri1,uri2,..)
form because open-uri
relies on URI.parse
to convert strings into URI
objects.
Parses a failover URI string or an array of URIs into a
OnStomp::Failover::URI::FAILOVER object. Ruby's URI parser works
fine with failover:(uri1,uri2,..)?params=..
style URIs, but chokes
on failover://uri1,uri2,..
forms. This method gives us a bit more
flexibility.
42 43 44 45 46 47 48 49 50 |
# File 'lib/onstomp/failover/uri.rb', line 42 def parse uri_str if uri_str =~ FAILOVER_REG uris = $1 query = $2 self.new uris.split(','), query else raise OnStomp::Failover::InvalidFailoverURIError, uri_str.inspect end end |
Instance Method Details
- (String) to_s
Converts a failover URI into a string. Ruby's Generic URIs don't seem to allow mixing opaques and queries.
22 23 24 25 |
# File 'lib/onstomp/failover/uri.rb', line 22 def to_s base = "#{scheme}:#{opaque}" query.nil? || query.empty? ? base : "#{base}?#{query}" end |