Module: Immortal::ClassMethods

Defined in:
lib/immortal.rb

Instance Method Summary collapse

Instance Method Details

#count_only_deleted(*args) ⇒ Object



44
45
46
47
48
# File 'lib/immortal.rb', line 44

def count_only_deleted(*args)
  without_default_scope do
    immortal.count(*args)
  end
end

#count_with_deleted(*args) ⇒ Object



38
39
40
41
42
# File 'lib/immortal.rb', line 38

def count_with_deleted(*args)
  without_default_scope do
    count(*args)
  end
end

#delete_all!(*args) ⇒ Object



66
67
68
# File 'lib/immortal.rb', line 66

def delete_all!(*args)
  unscoped.mortal_delete_all(*args)
end

#deleted_clause_sqlObject



74
75
76
# File 'lib/immortal.rb', line 74

def deleted_clause_sql
  unscoped.where(arel_table[COLUMN_NAME].eq(true)).constraints.first.to_sql
end

#exists?(id = false) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/immortal.rb', line 34

def exists?(id = false)
  mortal.exists?(id)
end

#immortal?Boolean

Returns whether the model supports immortal or not.

Returns:

  • (Boolean)

    whether the model supports immortal or not



22
23
24
# File 'lib/immortal.rb', line 22

def immortal?
  included_modules.include?(::Immortal::InstanceMethods)
end

#immortal_delete_all(conditions = nil) ⇒ Object



62
63
64
# File 'lib/immortal.rb', line 62

def immortal_delete_all(conditions = nil)
  unscoped.where(conditions).update_all(COLUMN_NAME => 1)
end

#undeleted_clause_sqlObject



70
71
72
# File 'lib/immortal.rb', line 70

def undeleted_clause_sql
  unscoped.mortal.constraints.first.to_sql
end

#where_only_deleted(conditions) ⇒ Object



56
57
58
59
60
# File 'lib/immortal.rb', line 56

def where_only_deleted(conditions)
  without_default_scope do
    immortal.where(conditions)
  end
end

#where_with_deleted(conditions) ⇒ Object



50
51
52
53
54
# File 'lib/immortal.rb', line 50

def where_with_deleted(conditions)
  without_default_scope do
    where(conditions)
  end
end

#without_default_scopeObject



26
27
28
29
30
31
32
# File 'lib/immortal.rb', line 26

def without_default_scope
  where_clause = (current_scope || unscoped).where_values_hash.except(COLUMN_NAME)

  unscoped.where(where_clause).scoping do
    yield
  end
end