Class: DataObjects::URI
- Inherits:
-
Struct
- Object
- Struct
- DataObjects::URI
- Defined in:
- lib/data_objects/uri.rb
Overview
A DataObjects URI is of the form scheme://user:password@host:port/path#fragment
The elements are all optional except scheme and path:
- scheme
-
The name of a DBMS for which you have a do_<scheme> adapter gem installed. If scheme is jdbc, the actual DBMS is in the path followed by a colon.
- user
-
The name of the user to authenticate to the database
- password
-
The password to use in authentication
- host
-
The domain name (defaulting to localhost) where the database is available
- port
-
The TCP/IP port number to use for the connection
- path
-
The name or path to the database
- query
-
Parameters for the connection, for example encoding=utf8
- fragment
-
Not currently known to be in use, but available to the adapters
Instance Attribute Summary collapse
-
#fragment ⇒ Object
Returns the value of attribute fragment.
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#path ⇒ Object
Returns the value of attribute path.
-
#port ⇒ Object
Returns the value of attribute port.
-
#query ⇒ Object
Returns the value of attribute query.
-
#scheme ⇒ Object
Returns the value of attribute scheme.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
-
.parse(uri) ⇒ Object
Make a DataObjects::URI object by parsing a string.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
Compare this URI to another for hashing.
-
#hash ⇒ Object
Hash this URI.
-
#to_s ⇒ Object
Display this URI object as a string.
Instance Attribute Details
#fragment ⇒ Object
Returns the value of attribute fragment
16 17 18 |
# File 'lib/data_objects/uri.rb', line 16 def fragment @fragment end |
#host ⇒ Object
Returns the value of attribute host
16 17 18 |
# File 'lib/data_objects/uri.rb', line 16 def host @host end |
#password ⇒ Object
Returns the value of attribute password
16 17 18 |
# File 'lib/data_objects/uri.rb', line 16 def password @password end |
#path ⇒ Object
Returns the value of attribute path
16 17 18 |
# File 'lib/data_objects/uri.rb', line 16 def path @path end |
#port ⇒ Object
Returns the value of attribute port
16 17 18 |
# File 'lib/data_objects/uri.rb', line 16 def port @port end |
#query ⇒ Object
Returns the value of attribute query
16 17 18 |
# File 'lib/data_objects/uri.rb', line 16 def query @query end |
#scheme ⇒ Object
Returns the value of attribute scheme
16 17 18 |
# File 'lib/data_objects/uri.rb', line 16 def scheme @scheme end |
#user ⇒ Object
Returns the value of attribute user
16 17 18 |
# File 'lib/data_objects/uri.rb', line 16 def user @user end |
Class Method Details
.parse(uri) ⇒ Object
Make a DataObjects::URI object by parsing a string. Simply delegates to Addressable::URI::parse.
18 19 20 21 22 |
# File 'lib/data_objects/uri.rb', line 18 def self.parse(uri) return uri if uri.kind_of?(self) uri = Addressable::URI::parse(uri) unless uri.kind_of?(Addressable::URI) self.new(uri.scheme, uri.user, uri.password, uri.host, uri.port, uri.path, uri.query_values, uri.fragment) end |
Instance Method Details
#eql?(other) ⇒ Boolean
Compare this URI to another for hashing
46 47 48 |
# File 'lib/data_objects/uri.rb', line 46 def eql?(other) to_s.eql?(other.to_s) end |
#hash ⇒ Object
Hash this URI
51 52 53 |
# File 'lib/data_objects/uri.rb', line 51 def hash to_s.hash end |
#to_s ⇒ Object
Display this URI object as a string
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/data_objects/uri.rb', line 25 def to_s string = "" string << "#{scheme}://" if scheme if user string << "#{user}" string << ":#{password}" if password string << "@" end string << "#{host}" if host string << ":#{port}" if port string << path.to_s if query string << "?" << query.map do |key, value| "#{key}=#{value}" end.join("&") end string << "##{fragment}" if fragment string end |