Class: Hanami::Model::Adapters::Rethinkdb::Collection Private
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Hanami::Model::Adapters::Rethinkdb::Collection
- Includes:
- RethinkDB::Shortcuts
- Defined in:
- lib/hanami/model/adapters/rethinkdb/collection.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.
Maps a RethinkDB database table and perfoms manipulations on it.
Instance Method Summary collapse
-
#avg(*args) ⇒ Numeric
private
Returns the average of the values for the given column.
-
#count ⇒ Numeric
private
Returns a count of the documents for the current conditions.
-
#delete ⇒ Object
private
Deletes the current scope.
-
#filter(*args) ⇒ Hanami::Model::Adapters::Rethinkdb::Collection
private
Filters the current scope with a ‘filter` directive.
-
#has_fields(*args) ⇒ Hanami::Model::Adapters::Rethinkdb::Collection
private
Filters the current scope with a ‘has_fields` directive.
-
#initialize(connection, dataset, mapped_collection) ⇒ Hanami::Model::Adapters::Rethinkdb::Collection
constructor
private
Initialize a collection.
-
#insert(entity) ⇒ Object
private
Creates a document for the given entity and assigns an id.
-
#limit(*args) ⇒ Hanami::Model::Adapters::Rethinkdb::Collection
private
Filters the current scope with a ‘limit` directive.
-
#max(field, *args) ⇒ Numeric
private
Returns the maximum value for the given field.
-
#min(field, *args) ⇒ Numeric
private
Returns the minimum value for the given field.
-
#order_by(*args) ⇒ Hanami::Model::Adapters::Rethinkdb::Collection
private
Filters the current scope with an ‘order_by` directive.
-
#pluck(*args) ⇒ Hanami::Model::Adapters::Rethinkdb::Collection
private
Filters the current scope with a ‘pluck` directive.
-
#sum(*args) ⇒ Numeric
private
Returns the sum of the values for the given field.
-
#to_a ⇒ Array
(also: #execute)
private
Resolves self by fetching the documents from the database and translating them into entities.
-
#update(entity) ⇒ Object
private
Updates the document corresponding to the given entity.
Constructor Details
#initialize(connection, dataset, mapped_collection) ⇒ Hanami::Model::Adapters::Rethinkdb::Collection
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 a collection
43 44 45 46 |
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 43 def initialize(connection, dataset, mapped_collection) super(dataset) @connection, @mapped_collection = connection, mapped_collection end |
Instance Method Details
#avg(*args) ⇒ Numeric
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 the average of the values for the given column.
202 203 204 205 206 |
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 202 def avg(*args) _run do super.default(nil) end end |
#count ⇒ Numeric
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 count of the documents for the current conditions.
250 251 252 253 254 |
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 250 def count _run do super end end |
#delete ⇒ 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 the current scope.
94 95 96 97 98 |
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 94 def delete _run do super end end |
#filter(*args) ⇒ Hanami::Model::Adapters::Rethinkdb::Collection
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.
Filters the current scope with a ‘filter` directive.
111 112 113 |
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 111 def filter(*args) _collection(super, @mapped_collection) end |
#has_fields(*args) ⇒ Hanami::Model::Adapters::Rethinkdb::Collection
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.
Filters the current scope with a ‘has_fields` directive.
141 142 143 |
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 141 def has_fields(*args) # rubocop:disable Style/PredicateName _collection(super, @mapped_collection) end |
#insert(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 for the given entity and assigns an id.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 58 def insert(entity) serialized_entity = _serialize(entity) response = _run do super(serialized_entity) end serialized_entity[_identity] = response['generated_keys'].first _deserialize([serialized_entity]).first end |
#limit(*args) ⇒ Hanami::Model::Adapters::Rethinkdb::Collection
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.
Filters the current scope with a ‘limit` directive.
156 157 158 |
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 156 def limit(*args) _collection(super, @mapped_collection) end |
#max(field, *args) ⇒ Numeric
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 the maximum value for the given field.
218 219 220 221 222 |
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 218 def max(field, *args) _run do super[field].default(nil) end end |
#min(field, *args) ⇒ Numeric
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 the minimum value for the given field.
234 235 236 237 238 |
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 234 def min(field, *args) _run do super[field].default(nil) end end |
#order_by(*args) ⇒ Hanami::Model::Adapters::Rethinkdb::Collection
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.
Filters the current scope with an ‘order_by` directive.
172 173 174 |
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 172 def order_by(*args) _collection(super, @mapped_collection) end |
#pluck(*args) ⇒ Hanami::Model::Adapters::Rethinkdb::Collection
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.
Filters the current scope with a ‘pluck` directive.
126 127 128 |
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 126 def pluck(*args) _collection(super, @mapped_collection) end |
#sum(*args) ⇒ Numeric
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 the sum of the values for the given field.
186 187 188 189 190 |
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 186 def sum(*args) _run do super end end |
#to_a ⇒ Array Also known as: execute
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.
Resolves self by fetching the documents from the database and translating them into entities.
263 264 265 266 267 268 269 |
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 263 def to_a _deserialize( _run do self end ) end |
#update(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 the document corresponding to the given entity.
78 79 80 81 82 83 84 85 86 |
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 78 def update(entity) serialized_entity = _serialize(entity) response = _run do super(serialized_entity) end _deserialize([serialized_entity]).first end |