Module: ActsAsParanoid::Core::ClassMethods

Defined in:
lib/acts_as_paranoid/core.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



8
9
10
# File 'lib/acts_as_paranoid/core.rb', line 8

def self.extended(base)
  base.define_callbacks :recover
end

Instance Method Details

#after_recover(method) ⇒ Object



16
17
18
# File 'lib/acts_as_paranoid/core.rb', line 16

def after_recover(method)
  set_callback :recover, :after, method
end

#before_recover(method) ⇒ Object



12
13
14
# File 'lib/acts_as_paranoid/core.rb', line 12

def before_recover(method)
  set_callback :recover, :before, method
end

#delete_all(conditions = nil) ⇒ Object



36
37
38
# File 'lib/acts_as_paranoid/core.rb', line 36

def delete_all(conditions = nil)
  update_all ["#{paranoid_configuration[:column]} = ?", delete_now_value], conditions
end

#delete_all!(conditions = nil) ⇒ Object



32
33
34
# File 'lib/acts_as_paranoid/core.rb', line 32

def delete_all!(conditions = nil)
  without_paranoid_default_scope.delete_all!(conditions)
end

#delete_now_valueObject



66
67
68
69
70
71
72
# File 'lib/acts_as_paranoid/core.rb', line 66

def delete_now_value
  case paranoid_configuration[:column_type]
  when "time" then Time.now
  when "boolean" then true
  when "string" then paranoid_configuration[:deleted_value]
  end
end

#dependent_associationsObject



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

def dependent_associations
  self.reflect_on_all_associations.select {|a| [:destroy, :delete_all].include?(a.options[:dependent]) }
end

#only_deletedObject



24
25
26
27
28
29
30
# File 'lib/acts_as_paranoid/core.rb', line 24

def only_deleted
  if string_type_with_deleted_value?
    without_paranoid_default_scope.where("#{paranoid_column_reference} IS ?", paranoid_configuration[:deleted_value])
  else
    without_paranoid_default_scope.where("#{paranoid_column_reference} IS NOT ?", nil)
  end
end

#paranoid_columnObject



54
55
56
# File 'lib/acts_as_paranoid/core.rb', line 54

def paranoid_column
  paranoid_configuration[:column].to_sym
end

#paranoid_column_typeObject



58
59
60
# File 'lib/acts_as_paranoid/core.rb', line 58

def paranoid_column_type
  paranoid_configuration[:column_type].to_sym
end

#paranoid_default_scope_sqlObject



40
41
42
43
44
45
46
47
48
# File 'lib/acts_as_paranoid/core.rb', line 40

def paranoid_default_scope_sql
  if string_type_with_deleted_value?
    self.scoped.table[paranoid_column].eq(nil).
      or(self.scoped.table[paranoid_column].not_eq(paranoid_configuration[:deleted_value])).
      to_sql
  else
    self.scoped.table[paranoid_column].eq(nil).to_sql
  end
end

#string_type_with_deleted_value?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/acts_as_paranoid/core.rb', line 50

def string_type_with_deleted_value?
  paranoid_column_type == :string && !paranoid_configuration[:deleted_value].nil?
end

#with_deletedObject



20
21
22
# File 'lib/acts_as_paranoid/core.rb', line 20

def with_deleted
  without_paranoid_default_scope
end