module Queryable::DefaultScope

Public Class Methods

included(base) click to toggle source

Internal: Adds class methods, and default initialization.

# File lib/queryable/default_scope.rb, line 7
def self.included(base)
  base.extend ClassMethods
end
new(*args) click to toggle source
Calls superclass method
# File lib/queryable/default_scope.rb, line 11
def initialize(*args)
  super
  apply_default_scopes
end

Private Instance Methods

apply_default_scope(scope) click to toggle source

Internal: Applies a default scope to this query object.

scope - A method name Symbol, or a Proc.

# File lib/queryable/default_scope.rb, line 27
def apply_default_scope(scope)
  scope.is_a?(Proc) ? instance_exec(&scope) : send(scope)
end
apply_default_scopes() click to toggle source

Internal: Applies all the default scopes to this query object.

# File lib/queryable/default_scope.rb, line 19
def apply_default_scopes
  self.class.default_scopes.each { |scope| apply_default_scope(scope) }
end