Module: CollectiveIdea::NamedScope

Defined in:
lib/awesome_nested_set/named_scope.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ClassMethods Classes: Scope

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

All subclasses of ActiveRecord::Base have two named_scopes:

  • all, which is similar to a find(:all) query, and

  • scoped, which allows for the creation of anonymous scopes, on the fly:

    Shirt.scoped(:conditions => => ‘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.



12
13
14
15
16
17
# File 'lib/awesome_nested_set/named_scope.rb', line 12

def self.included(base)
  base.class_eval do
    extend ClassMethods
    named_scope :scoped, lambda { |scope| scope }
  end
end