Module: Queryable::DefaultScope::ClassMethods
- Defined in:
- lib/queryable/default_scope.rb
Instance Method Summary collapse
-
#default_scope(scope) ⇒ Object
Public: Allows a class to set a default scope.
-
#default_scopes ⇒ Object
Internal: Returns the default scopes that should be applied.
-
#parent_scopes ⇒ Object
Internal: Returns the default scopes of the parent query objects.
Instance Method Details
#default_scope(scope) ⇒ Object
Public: Allows a class to set a default scope. Default scopes are chainable with inheritance, so a subclass also picks up the default scopes of the parent class.
scope - A method name Symbol, or a Proc.
38 39 40 |
# File 'lib/queryable/default_scope.rb', line 38 def default_scope(scope) @default_scope = scope end |
#default_scopes ⇒ Object
Internal: Returns the default scopes that should be applied.
48 49 50 |
# File 'lib/queryable/default_scope.rb', line 48 def default_scopes @default_scopes ||= (parent_scopes + [@default_scope]).compact end |
#parent_scopes ⇒ Object
Internal: Returns the default scopes of the parent query objects.
43 44 45 |
# File 'lib/queryable/default_scope.rb', line 43 def parent_scopes superclass.respond_to?(:default_scopes) ? superclass.default_scopes : [] end |