Class: DataObjects::URI

Inherits:
Struct
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fragmentObject

Returns the value of attribute fragment

Returns:

  • (Object)

    the current value of fragment



16
17
18
# File 'lib/data_objects/uri.rb', line 16

def fragment
  @fragment
end

#hostObject

Returns the value of attribute host

Returns:

  • (Object)

    the current value of host



16
17
18
# File 'lib/data_objects/uri.rb', line 16

def host
  @host
end

#passwordObject

Returns the value of attribute password

Returns:

  • (Object)

    the current value of password



16
17
18
# File 'lib/data_objects/uri.rb', line 16

def password
  @password
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



16
17
18
# File 'lib/data_objects/uri.rb', line 16

def path
  @path
end

#portObject

Returns the value of attribute port

Returns:

  • (Object)

    the current value of port



16
17
18
# File 'lib/data_objects/uri.rb', line 16

def port
  @port
end

#queryObject

Returns the value of attribute query

Returns:

  • (Object)

    the current value of query



16
17
18
# File 'lib/data_objects/uri.rb', line 16

def query
  @query
end

#schemeObject

Returns the value of attribute scheme

Returns:

  • (Object)

    the current value of scheme



16
17
18
# File 'lib/data_objects/uri.rb', line 16

def scheme
  @scheme
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of 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

Returns:

  • (Boolean)


46
47
48
# File 'lib/data_objects/uri.rb', line 46

def eql?(other)
  to_s.eql?(other.to_s)
end

#hashObject

Hash this URI



51
52
53
# File 'lib/data_objects/uri.rb', line 51

def hash
  to_s.hash
end

#to_sObject

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