Class: HyperionUri
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- HyperionUri
- Defined in:
- lib/hyperion/types/hyperion_uri.rb
Instance Attribute Summary collapse
-
#query_hash ⇒ Object
An enhanced version of URI.
Instance Method Summary collapse
-
#base ⇒ String
The URI base e.g., “http://somehost:80”.
- #base=(uri) ⇒ Object
-
#initialize(uri, query_hash = {}) ⇒ HyperionUri
constructor
A new instance of HyperionUri.
- #inspect ⇒ Object
- #query ⇒ Object
- #query=(query) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(uri, query_hash = {}) ⇒ HyperionUri
Returns a new instance of HyperionUri.
15 16 17 18 19 20 21 |
# File 'lib/hyperion/types/hyperion_uri.rb', line 15 def initialize(uri, query_hash={}) @uri = make_ruby_uri(uri) query_from_uri = parse_query(@uri.query) additional_query_params = validate_query(query_hash) @query_hash = query_from_uri.merge(additional_query_params) __setobj__(@uri) end |
Instance Attribute Details
#query_hash ⇒ Object
An enhanced version of URI. Namely,
-
the base uri is a first class citizen,
-
it accepts a hash containing query key/values, and
-
it form-encodes query values that are arrays.
13 14 15 |
# File 'lib/hyperion/types/hyperion_uri.rb', line 13 def query_hash @query_hash end |
Instance Method Details
#base ⇒ String
Returns the URI base e.g., “http://somehost:80”.
42 43 44 |
# File 'lib/hyperion/types/hyperion_uri.rb', line 42 def base "#{scheme}://#{host}:#{port}" end |
#base=(uri) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/hyperion/types/hyperion_uri.rb', line 46 def base=(uri) uri = uri.is_a?(HyperionUri) ? uri : HyperionUri.new(uri) self.scheme = uri.scheme self.host = uri.host self.port = uri.port end |
#inspect ⇒ Object
37 38 39 |
# File 'lib/hyperion/types/hyperion_uri.rb', line 37 def inspect "#<HyperionUri:0x#{(object_id << 1).to_s(16)} #{to_s}>" end |
#query ⇒ Object
23 24 25 |
# File 'lib/hyperion/types/hyperion_uri.rb', line 23 def query query_string(@query_hash) end |
#query=(query) ⇒ Object
27 28 29 |
# File 'lib/hyperion/types/hyperion_uri.rb', line 27 def query=(query) @query_hash = parse_query(query) end |
#to_s ⇒ Object
31 32 33 34 35 |
# File 'lib/hyperion/types/hyperion_uri.rb', line 31 def to_s fixed = @uri.dup fixed.query = query make_ruby_uri(fixed).to_s end |