Class: Hanami::Model::Adapters::Rethinkdb::Collection Private

Inherits:
SimpleDelegator
  • Object
show all
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.

Since:

  • 0.1.0

API:

  • private

Instance Method Summary collapse

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

Parameters:

  • the connection to the database

  • the dataset that maps a table or a subset of it

  • a mapped collection

Since:

  • 0.1.0

API:

  • private



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.

Parameters:

  • the array of arguments

Returns:

See Also:

Since:

  • 0.1.0

API:

  • private



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

#countNumeric

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.

Parameters:

  • the array of arguments

Returns:

See Also:

Since:

  • 0.1.0

API:

  • private



250
251
252
253
254
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 250

def count
  _run do
    super
  end
end

#deleteObject

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.

See Also:

Since:

  • 0.1.0

API:

  • private



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.

Parameters:

  • the array of arguments

Returns:

  • the filtered collection

See Also:

Since:

  • 0.1.0

API:

  • private



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.

Parameters:

  • the array of arguments

Returns:

  • the filtered collection

See Also:

Since:

  • 0.1.0

API:

  • private



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.

Parameters:

  • the entity to persist

Returns:

  • the primary key of the created document

See Also:

Since:

  • 0.1.0

API:

  • private



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.

Parameters:

  • the array of arguments

Returns:

  • the filtered collection

See Also:

Since:

  • 0.1.0

API:

  • private



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.

Parameters:

  • the array of arguments

Returns:

See Also:

Since:

  • 0.1.0

API:

  • private



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.

Parameters:

  • the array of arguments

Returns:

See Also:

Since:

  • 0.1.0

API:

  • private



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.

Parameters:

  • the array of arguments

Returns:

  • the filtered collection

See Also:

Since:

  • 0.1.0

API:

  • private



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.

Parameters:

  • the array of arguments

Returns:

  • the filtered collection

See Also:

Since:

  • 0.1.0

API:

  • private



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.

Parameters:

  • the array of arguments

Returns:

See Also:

Since:

  • 0.1.0

API:

  • private



186
187
188
189
190
# File 'lib/hanami/model/adapters/rethinkdb/collection.rb', line 186

def sum(*args)
  _run do
    super
  end
end

#to_aArray 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.

Returns:

  • the result of the query

Since:

  • 0.1.0

API:

  • private



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.

Parameters:

  • the entity to persist

See Also:

Since:

  • 0.1.0

API:

  • private



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