Module: Kakurenbo::Core::Scopes

Defined in:
lib/kakurenbo/core.rb

Class Method Summary collapse

Class Method Details

.extended(base_class) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kakurenbo/core.rb', line 38

def self.extended(base_class)
  base_class.instance_eval {
    scope :only_deleted,    ->{ with_deleted.where.not( kakurenbo_column => nil ) }
    scope :without_deleted, ->{ where(kakurenbo_column => nil) }
    if ActiveRecord::VERSION::STRING >= "4.1"
      scope :with_deleted,  ->{ unscope :where => kakurenbo_column }
    else
      scope :with_deleted,  ->{ all.tap{ |s| s.default_scoped = false } }
    end

    default_scope ->{ without_deleted }
  }
end