Class: Mongo::Configure::URI

Inherits:
Struct
  • Object
show all
Defined in:
lib/mongo/configure/uri.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scheme = 'mongodb', host = 'localhost', port = '27017', database = '', user = nil, password = nil) ⇒ URI

Returns a new instance of URI.



4
5
6
# File 'lib/mongo/configure/uri.rb', line 4

def initialize(scheme='mongodb',host='localhost',port='27017',database='',user=nil,password=nil)
  super
end

Instance Attribute Details

#databaseObject

Returns the value of attribute database

Returns:

  • (Object)

    the current value of database



3
4
5
# File 'lib/mongo/configure/uri.rb', line 3

def database
  @database
end

#hostObject

Returns the value of attribute host

Returns:

  • (Object)

    the current value of host



3
4
5
# File 'lib/mongo/configure/uri.rb', line 3

def host
  @host
end

#passwordObject

Returns the value of attribute password

Returns:

  • (Object)

    the current value of password



3
4
5
# File 'lib/mongo/configure/uri.rb', line 3

def password
  @password
end

#portObject

Returns the value of attribute port

Returns:

  • (Object)

    the current value of port



3
4
5
# File 'lib/mongo/configure/uri.rb', line 3

def port
  @port
end

#schemeObject

Returns the value of attribute scheme

Returns:

  • (Object)

    the current value of scheme



3
4
5
# File 'lib/mongo/configure/uri.rb', line 3

def scheme
  @scheme
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of user



3
4
5
# File 'lib/mongo/configure/uri.rb', line 3

def user
  @user
end

Class Method Details

.parse(string) ⇒ Object



8
9
10
11
# File 'lib/mongo/configure/uri.rb', line 8

def self.parse(string)
  uri = ::URI.parse string
  new uri.scheme, uri.host, uri.port.to_s, uri.path.gsub(/^\//,''), uri.user, uri.password
end

Instance Method Details

#authObject



12
13
14
15
16
17
18
# File 'lib/mongo/configure/uri.rb', line 12

def auth
  if user || password
    [user,password].join(':')+'@'
  else
    ''
  end
end

#to_sObject



19
20
21
# File 'lib/mongo/configure/uri.rb', line 19

def to_s
  "#{scheme}://#{auth}#{host}:#{port}/#{database}"
end