Class: ROM::Mongo::Repository

Inherits:
Repository
  • Object
show all
Defined in:
lib/rom/mongo/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Repository

Returns a new instance of Repository.



18
19
20
21
22
23
# File 'lib/rom/mongo/repository.rb', line 18

def initialize(uri)
  host, database = uri.split('/')
  @connection = Moped::Session.new([host])
  @connection.use database
  @collections = {}
end

Instance Attribute Details

#collectionsObject (readonly)

Returns the value of attribute collections.



16
17
18
# File 'lib/rom/mongo/repository.rb', line 16

def collections
  @collections
end

Instance Method Details

#[](name) ⇒ Object



25
26
27
# File 'lib/rom/mongo/repository.rb', line 25

def [](name)
  collections.fetch(name)
end

#command_namespaceObject



37
38
39
# File 'lib/rom/mongo/repository.rb', line 37

def command_namespace
  Mongo::Commands
end

#dataset(name) ⇒ Object



29
30
31
# File 'lib/rom/mongo/repository.rb', line 29

def dataset(name)
  collections[name] = Dataset.new(connection[name])
end

#dataset?(name) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/rom/mongo/repository.rb', line 33

def dataset?(name)
  connection.collection_names.include?(name.to_s)
end