Module: Friendly::Document::Scoping::ClassMethods
- Defined in:
- lib/friendly/document/scoping.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#has_named_scope?(name) ⇒ Boolean
Returns boolean based on whether the Document has a scope by a particular name.
-
#named_scope(name, parameters) ⇒ Object
Add a named scope to this Document.
-
#scope(parameters) ⇒ Object
Create an ad hoc scope on this Document.
Instance Attribute Details
#scope_proxy ⇒ Object
11 12 13 |
# File 'lib/friendly/document/scoping.rb', line 11 def scope_proxy @scope_proxy ||= ScopeProxy.new(self) end |
Instance Method Details
#has_named_scope?(name) ⇒ Boolean
Returns boolean based on whether the Document has a scope by a particular name.
47 48 49 |
# File 'lib/friendly/document/scoping.rb', line 47 def has_named_scope?(name) scope_proxy.has_named_scope?(name) end |
#named_scope(name, parameters) ⇒ Object
Add a named scope to this Document.
e.g.
class Post
indexes :created_at
named_scope :recent, :order! => :created_at.desc
end
Then, you can access the recent posts with:
Post.recent.all
…or…
Post.recent.first
Both #all and #first also take additional parameters:
Post.recent.all(:author_id => @author.id)
Scopes are also chainable. See the README or Friendly::Scope docs for details.
39 40 41 |
# File 'lib/friendly/document/scoping.rb', line 39 def named_scope(name, parameters) scope_proxy.add_named(name, parameters) end |
#scope(parameters) ⇒ Object
Create an ad hoc scope on this Document.
e.g.
scope = Post.scope(:order! => :created_at)
scope.all # => [#<Post>, #<Post>]
60 61 62 |
# File 'lib/friendly/document/scoping.rb', line 60 def scope(parameters) scope_proxy.ad_hoc(parameters) end |