lib/lotus/model/adapters/sql/collection.rb in lotus-model-0.1.2 vs lib/lotus/model/adapters/sql/collection.rb in lotus-model-0.2.0
- old
+ new
@@ -15,20 +15,20 @@
class Collection < SimpleDelegator
# Initialize a collection
#
# @param dataset [Sequel::Dataset] the dataset that maps a table or a
# subset of it.
- # @param collection [Lotus::Model::Mapping::Collection] a mapped
- # collection
+ # @param mapped_collection [Lotus::Model::Mapping::Collection] a
+ # mapped collection
#
# @return [Lotus::Model::Adapters::Sql::Collection]
#
# @api private
# @since 0.1.0
- def initialize(dataset, collection)
+ def initialize(dataset, mapped_collection)
super(dataset)
- @collection = collection
+ @mapped_collection = mapped_collection
end
# Filters the current scope with an `exclude` directive.
#
# @param args [Array] the array of arguments
@@ -39,11 +39,11 @@
# collection
#
# @api private
# @since 0.1.0
def exclude(*args)
- Collection.new(super, @collection)
+ Collection.new(super, @mapped_collection)
end
# Creates a record for the given entity and assigns an id.
#
# @param entity [Object] the entity to persist
@@ -56,11 +56,11 @@
# @since 0.1.0
def insert(entity)
super _serialize(entity)
end
- # Filters the current scope with an `limit` directive.
+ # Filters the current scope with a `limit` directive.
#
# @param args [Array] the array of arguments
#
# @see Lotus::Model::Adapters::Sql::Query#limit
#
@@ -68,11 +68,11 @@
# collection
#
# @api private
# @since 0.1.0
def limit(*args)
- Collection.new(super, @collection)
+ Collection.new(super, @mapped_collection)
end
# Filters the current scope with an `offset` directive.
#
# @param args [Array] the array of arguments
@@ -83,11 +83,11 @@
# collection
#
# @api private
# @since 0.1.0
def offset(*args)
- Collection.new(super, @collection)
+ Collection.new(super, @mapped_collection)
end
# Filters the current scope with an `or` directive.
#
# @param args [Array] the array of arguments
@@ -98,11 +98,11 @@
# collection
#
# @api private
# @since 0.1.0
def or(*args)
- Collection.new(super, @collection)
+ Collection.new(super, @mapped_collection)
end
# Filters the current scope with an `order` directive.
#
# @param args [Array] the array of arguments
@@ -113,11 +113,11 @@
# collection
#
# @api private
# @since 0.1.0
def order(*args)
- Collection.new(super, @collection)
+ Collection.new(super, @mapped_collection)
end
# Filters the current scope with an `order` directive.
#
# @param args [Array] the array of arguments
@@ -128,14 +128,14 @@
# collection
#
# @api private
# @since 0.1.0
def order_more(*args)
- Collection.new(super, @collection)
+ Collection.new(super, @mapped_collection)
end
- # Filters the current scope with an `select` directive.
+ # Filters the current scope with a `select` directive.
#
# @param args [Array] the array of arguments
#
# @see Lotus::Model::Adapters::Sql::Query#select
#
@@ -144,19 +144,19 @@
#
# @api private
# @since 0.1.0
if RUBY_VERSION >= '2.1'
def select(*args)
- Collection.new(super, @collection)
+ Collection.new(super, @mapped_collection)
end
else
def select(*args)
- Collection.new(__getobj__.select(*Lotus::Utils::Kernel.Array(args)), @collection)
+ Collection.new(__getobj__.select(*Lotus::Utils::Kernel.Array(args)), @mapped_collection)
end
end
- # Filters the current scope with an `where` directive.
+ # Filters the current scope with a `where` directive.
#
# @param args [Array] the array of arguments
#
# @see Lotus::Model::Adapters::Sql::Query#where
#
@@ -164,11 +164,11 @@
# collection
#
# @api private
# @since 0.1.0
def where(*args)
- Collection.new(super, @collection)
+ Collection.new(super, @mapped_collection)
end
# Updates the record corresponding to the given entity.
#
# @param entity [Object] the entity to persist
@@ -187,21 +187,21 @@
# @return [Array] the result of the query
#
# @api private
# @since 0.1.0
def to_a
- @collection.deserialize(self)
+ @mapped_collection.deserialize(self)
end
private
# Serialize the given entity before to persist in the database.
#
# @return [Hash] the serialized entity
#
# @api private
# @since 0.1.0
def _serialize(entity)
- @collection.serialize(entity)
+ @mapped_collection.serialize(entity)
end
end
end
end
end