module Queryable::DefaultScope::ClassMethods

Public Instance Methods

default_scope(scope) click to toggle source

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.

# File lib/queryable/default_scope.rb, line 38
def default_scope(scope)
  @default_scope = scope
end
default_scopes() click to toggle source

Internal: Returns the default scopes that should be applied.

# File lib/queryable/default_scope.rb, line 48
def default_scopes
  @default_scopes ||= (parent_scopes + [@default_scope]).compact
end
parent_scopes() click to toggle source

Internal: Returns the default scopes of the parent query objects.

# File lib/queryable/default_scope.rb, line 43
def parent_scopes
  superclass.respond_to?(:default_scopes) ? superclass.default_scopes : []
end