Parent

Mongo::URIParser

Attributes

auths[R]
connect[R]
fsync[R]
nodes[R]
replicaset[R]
safe[R]
slaveok[R]
w[R]
wtimeout[R]

Public Class Methods

new(string) click to toggle source

Parse a MongoDB URI. This method is used by Connection.from_uri. Returns an array of nodes and an array of db authorizations, if applicable.

Note: passwords can contain any character except for a ','.

@core connections

# File lib/mongo/util/uri_parser.rb, line 62
def initialize(string)
  if string =~ /^mongodb:\/\//
    string = string[10..-1]
  else
    raise MongoArgumentError, "MongoDB URI must match this spec: #{MONGODB_URI_SPEC}"
  end

  hosts, opts = string.split('?')
  parse_hosts(hosts)
  parse_options(opts)
  configure_connect
end

Public Instance Methods

connection_options() click to toggle source
# File lib/mongo/util/uri_parser.rb, line 75
def connection_options
  opts = {}

  if (@w || @wtimeout || @fsync) && !@safe
    raise MongoArgumentError, "Safe must be true if w, wtimeout, or fsync is specified"
  end

  if @safe
    if @w || @wtimeout || @fsync
      safe_opts = {}
      safe_opts[:w] = @w if @w
      safe_opts[:wtimeout] = @wtimeout if @wtimeout
      safe_opts[:fsync] = @fsync if @fsync
    else
      safe_opts = true
    end

    opts[:safe] = safe_opts
  end

  if @slaveok
    if @connect == 'direct'
      opts[:slave_ok] = true
    else
      opts[:read_secondary] = true
    end
  end

  opts[:rs_name] = @replicaset if @replicaset

  opts
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.