Class: Hanami::Model::Adapters::RethinkdbAdapter Private
- Inherits:
-
Abstract
- Object
- Abstract
- Hanami::Model::Adapters::RethinkdbAdapter
- Includes:
- RethinkDB::Shortcuts
- Defined in:
- lib/hanami/model/adapters/rethinkdb_adapter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Adapter for RethinkDB databases
Instance Attribute Summary collapse
- #parsed_uri ⇒ Object readonly private
Instance Method Summary collapse
-
#all(collection) ⇒ Array
private
Returns all the documents for the given collection.
-
#clear(collection) ⇒ Object
private
Deletes all the documents from the given collection.
-
#command(query) ⇒ Hanami::Model::Adapters::Rethinkdb::Command
private
Fabricates a command for the given query.
-
#create(collection, entity) ⇒ Object
private
Creates a document in the database for the given entity.
-
#delete(collection, entity) ⇒ Object
private
Deletes a document in the database corresponding to the given entity.
-
#find(collection, id) ⇒ Object
private
Returns a unique document from the given collection, with the given id.
-
#first(_collection) ⇒ Object
private
This method is not implemented.
-
#initialize(mapper, uri, options = {}) ⇒ Hanami::Model::Adapters::RethinkdbAdapter
constructor
private
Initialize the adapter.
-
#last(_collection) ⇒ Object
private
This method is not implemented.
-
#persist(collection, entity) ⇒ Object
private
Creates or updates a document in the database for the given entity.
-
#query(collection, context = nil, &blk) ⇒ Hanami::Model::Adapters::Rethinkdb::Query
private
Fabricates a query.
-
#update(collection, entity) ⇒ Object
private
Updates a document in the database corresponding to the given entity.
Constructor Details
#initialize(mapper, uri, options = {}) ⇒ Hanami::Model::Adapters::RethinkdbAdapter
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.
Initialize the adapter.
Hanami::Model uses RethinkDB.
51 52 53 54 |
# File 'lib/hanami/model/adapters/rethinkdb_adapter.rb', line 51 def initialize(mapper, uri, ={}) super @connection = r.connect(_parse_uri) end |
Instance Attribute Details
#parsed_uri ⇒ Object (readonly)
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.
35 36 37 |
# File 'lib/hanami/model/adapters/rethinkdb_adapter.rb', line 35 def parsed_uri @parsed_uri end |
Instance Method Details
#all(collection) ⇒ Array
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.
Returns all the documents for the given collection
129 130 131 |
# File 'lib/hanami/model/adapters/rethinkdb_adapter.rb', line 129 def all(collection) query(collection).all end |
#clear(collection) ⇒ Object
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.
Deletes all the documents from the given collection.
179 180 181 |
# File 'lib/hanami/model/adapters/rethinkdb_adapter.rb', line 179 def clear(collection) command(query(collection)).clear end |
#command(query) ⇒ Hanami::Model::Adapters::Rethinkdb::Command
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.
Fabricates a command for the given query.
object to act on.
194 195 196 |
# File 'lib/hanami/model/adapters/rethinkdb_adapter.rb', line 194 def command(query) Rethinkdb::Command.new(query) end |
#create(collection, entity) ⇒ Object
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.
Creates a document in the database for the given entity. It assigns the ‘id` attribute, in case of success.
84 85 86 87 88 89 |
# File 'lib/hanami/model/adapters/rethinkdb_adapter.rb', line 84 def create(collection, entity) ::Kernel.raise Adapters::RethinkdbIOError.new(collection, 'create') if entity.nil? command( query(collection) ).create(entity) end |
#delete(collection, entity) ⇒ Object
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.
Deletes a document in the database corresponding to the given entity.
114 115 116 117 118 119 |
# File 'lib/hanami/model/adapters/rethinkdb_adapter.rb', line 114 def delete(collection, entity) ::Kernel.raise RethinkdbIOError.new(collection, 'delete') if entity.nil? command( _find(collection, entity.id) ).delete end |
#find(collection, id) ⇒ Object
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.
Returns a unique document from the given collection, with the given id.
143 144 145 146 147 |
# File 'lib/hanami/model/adapters/rethinkdb_adapter.rb', line 143 def find(collection, id) _first( _find(collection, id) ) end |
#first(_collection) ⇒ Object
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.
This method is not implemented. RethinkDB does not have sequential primary keys.
157 158 159 |
# File 'lib/hanami/model/adapters/rethinkdb_adapter.rb', line 157 def first(_collection) fail NotImplementedError end |
#last(_collection) ⇒ Object
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.
This method is not implemented. RethinkDB does not have sequential primary keys.
169 170 171 |
# File 'lib/hanami/model/adapters/rethinkdb_adapter.rb', line 169 def last(_collection) fail NotImplementedError end |
#persist(collection, entity) ⇒ Object
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.
Creates or updates a document in the database for the given entity.
65 66 67 68 69 70 71 72 |
# File 'lib/hanami/model/adapters/rethinkdb_adapter.rb', line 65 def persist(collection, entity) ::Kernel.raise RethinkdbIOError.new(collection, 'IO') if entity.nil? if entity.id update(collection, entity) else create(collection, entity) end end |
#query(collection, context = nil, &blk) ⇒ Hanami::Model::Adapters::Rethinkdb::Query
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.
Fabricates a query
210 211 212 |
# File 'lib/hanami/model/adapters/rethinkdb_adapter.rb', line 210 def query(collection, context = nil, &blk) Rethinkdb::Query.new(_collection(collection), context, &blk) end |
#update(collection, entity) ⇒ Object
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.
Updates a document in the database corresponding to the given entity.
100 101 102 103 104 105 |
# File 'lib/hanami/model/adapters/rethinkdb_adapter.rb', line 100 def update(collection, entity) ::Kernel.raise RethinkdbIOError.new(collection, 'update') if entity.nil? command( _find(collection, entity.id) ).update(entity) end |