Class: ROM::Mongo::Repository
- Inherits:
-
Repository
- Object
- Repository
- ROM::Mongo::Repository
- Defined in:
- lib/rom/mongo/repository.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
readonly
Returns the value of attribute collections.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #command_namespace ⇒ Object
- #dataset(name) ⇒ Object
- #dataset?(name) ⇒ Boolean
-
#initialize(uri) ⇒ Repository
constructor
A new instance of Repository.
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
#collections ⇒ Object (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_namespace ⇒ Object
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
33 34 35 |
# File 'lib/rom/mongo/repository.rb', line 33 def dataset?(name) connection.collection_names.include?(name.to_s) end |