Module: CouchFoo::NamedScope
- Defined in:
- lib/couch_foo/named_scope.rb
Defined Under Namespace
Modules: ClassMethods Classes: Scope
Class Method Summary collapse
-
.included(base) ⇒ Object
All subclasses of CouchFoo::Base have two named_scopes: *
all
, which is similar to afind(:all)
query, and *scoped
, which allows for the creation of anonymous scopes, on the fly:Shirt.scoped(:conditions => {:color => 'red'}).scoped(:include => :washing_instructions)
.
Class Method Details
.included(base) ⇒ Object
All subclasses of CouchFoo::Base have two named_scopes:
-
all
, which is similar to afind(:all)
query, and -
scoped
, which allows for the creation of anonymous scopes, on the fly:Shirt.scoped(:conditions => {:color => 'red'}).scoped(:include => :washing_instructions)
These anonymous scopes tend to be useful when procedurally generating complex queries, where passing intermediate values (scopes) around as first-class objects is convenient.
9 10 11 12 13 14 |
# File 'lib/couch_foo/named_scope.rb', line 9 def self.included(base) base.class_eval do extend ClassMethods named_scope :scoped, lambda { |scope| scope } end end |