Permalink
Browse files

Move common code into queryable from contexts

  • Loading branch information...
1 parent 2ee6633 commit f4585d50d5c81ef7a5a27ade2d9da6bddd53e5d2 @durran durran committed Sep 15, 2012
@@ -1,4 +1,5 @@
# encoding: utf-8
+require "mongoid/contextual/queryable"
require "mongoid/contextual/memory"
require "mongoid/contextual/mongo"
@@ -6,22 +6,13 @@ module Contextual
class Memory
include Enumerable
include Aggregable::Memory
+ include Queryable
- # @attribute [r] collection The root collection.
- # @attribute [r] criteria The criteria for the context.
- # @attribute [r] klass The criteria class.
# @attribute [r] root The root document.
# @attribute [r] path The atomic path.
# @attribute [r] selector The root document selector.
# @attribute [r] matching The in memory documents that match the selector.
- attr_reader \
- :collection,
- :criteria,
- :documents,
- :klass,
- :path,
- :root,
- :selector
+ attr_reader :documents, :path, :root, :selector
# Check if the context is equal to the other object.
#
@@ -38,19 +29,6 @@ def ==(other)
entries == other.entries
end
- # Is the enumerable of matching documents empty?
- #
- # @example Is the context empty?
- # context.blank?
- #
- # @return [ true, false ] If the context is empty.
- #
- # @since 3.0.0
- def blank?
- count == 0
- end
- alias :empty? :blank?
-
# Delete all documents in the database that match the selector.
#
# @example Delete all the documents.
@@ -11,12 +11,10 @@ class Mongo
include Enumerable
include Aggregable::Mongo
include Atomic
+ include Queryable
- # @attribute [r] collection The collection to query against.
- # @attribute [r] criteria The criteria for the context.
- # @attribute [r] klass The klass for the criteria.
# @attribute [r] query The Moped query.
- attr_reader :collection, :criteria, :klass, :query
+ attr_reader :query
# @attribute [rw] eager_loaded Has the context been eager loaded?
attr_accessor :eager_loaded
@@ -0,0 +1,25 @@
+# encoding: utf-8
+module Mongoid
+ module Contextual
+ module Queryable
+
+ # @attribute [r] collection The collection to query against.
+ # @attribute [r] criteria The criteria for the context.
+ # @attribute [r] klass The klass for the criteria.
+ attr_reader :collection, :criteria, :klass
+
+ # Is the enumerable of matching documents empty?
+ #
+ # @example Is the context empty?
+ # context.blank?
+ #
+ # @return [ true, false ] If the context is empty.
+ #
+ # @since 3.0.0
+ def blank?
+ !exists?
+ end
+ alias :empty? :blank?
+ end
+ end
+end

0 comments on commit f4585d5

Please sign in to comment.