Class: ROM::Mongo::Gateway
- Inherits:
-
Gateway
- Object
- Gateway
- ROM::Mongo::Gateway
- Defined in:
- lib/rom/mongo/gateway.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
readonly
Returns the value of attribute collections.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #command_namespace ⇒ Object
- #dataset(name) ⇒ Object
- #dataset?(name) ⇒ Boolean
-
#initialize(uri, options = EMPTY_HASH) ⇒ Mongo::Gateway
constructor
Initialize an Mongo gateway.
-
#schema ⇒ Array<Symbol>
private
List of defined collections.
Constructor Details
#initialize(uri) ⇒ Mongo::Gateway #initialize(uri, options) ⇒ Mongo::Gateway #initialize(connection) ⇒ Mongo::Gateway
Initialize an Mongo gateway
Gateways are typically initialized via ROM::Configuration object, gateway constructor arguments such as URI and options are passed directly to this constructor
64 65 66 67 |
# File 'lib/rom/mongo/gateway.rb', line 64 def initialize(uri, = EMPTY_HASH) @connection = uri.is_a?(::Mongo::Client) ? uri : ::Mongo::Client.new(uri, ) @collections = {} end |
Instance Attribute Details
#collections ⇒ Object (readonly)
Returns the value of attribute collections.
14 15 16 |
# File 'lib/rom/mongo/gateway.rb', line 14 def collections @collections end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
18 19 20 |
# File 'lib/rom/mongo/gateway.rb', line 18 def @options end |
Instance Method Details
#[](name) ⇒ Object
78 79 80 |
# File 'lib/rom/mongo/gateway.rb', line 78 def [](name) collections.fetch(name) end |
#command_namespace ⇒ Object
90 91 92 |
# File 'lib/rom/mongo/gateway.rb', line 90 def command_namespace Mongo::Commands end |
#dataset(name) ⇒ Object
82 83 84 |
# File 'lib/rom/mongo/gateway.rb', line 82 def dataset(name) collections[name] = Dataset.new(connection[name]) end |
#dataset?(name) ⇒ Boolean
86 87 88 |
# File 'lib/rom/mongo/gateway.rb', line 86 def dataset?(name) connection.database.collection_names.include?(name.to_s) end |
#schema ⇒ Array<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
List of defined collections
74 75 76 |
# File 'lib/rom/mongo/gateway.rb', line 74 def schema connection.database.collection_names.map(&:to_sym) end |