Module: Scruber::Mongo::Factory

Extended by:
Factory
Included in:
Factory
Defined in:
lib/scruber/mongo/factory.rb

Instance Method Summary collapse

Instance Method Details

#create_client(client_name = :default) ⇒ Object

Raises:

  • (Scruber::ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/scruber/mongo/factory.rb', line 6

def create_client(client_name=:default)
  raise Scruber::ArgumentError.new("Not configured") unless Scruber::Mongo.configuration.configured?(client_name)
  configuration = Scruber::Mongo.configuration.clients[client_name]
  if configuration[:uri]
    ::Mongo::Client.new(configuration[:uri], options(configuration))
  else
    ::Mongo::Client.new(
      configuration[:hosts],
      options(configuration).merge(database: configuration[:database])
    )
  end
end

#options(configuration) ⇒ Object



19
20
21
22
23
# File 'lib/scruber/mongo/factory.rb', line 19

def options(configuration)
  config = configuration.dup
  options = config.delete(:options) || {}
  options.reject{ |k, v| k == :hosts }.to_hash.symbolize_keys!
end