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

#column_type_with_deleted_value?Boolean

Returns:

  • (Boolean)


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

def column_type_with_deleted_value?
  [:string, :boolean].include?(paranoid_column_type) && !paranoid_configuration[:deleted_value].nil?
end

#delete_all(conditions = nil) ⇒ Object



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

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

#delete_all!(conditions = nil) ⇒ Object



29
30
31
# File 'lib/acts_as_paranoid/core.rb', line 29

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

#delete_now_valueObject



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

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



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

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

#only_deletedObject



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

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

#paranoid_columnObject



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

def paranoid_column
  paranoid_configuration[:column].to_sym
end

#paranoid_column_typeObject



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

def paranoid_column_type
  paranoid_configuration[:column_type].to_sym
end

#paranoid_default_scope_sqlObject



37
38
39
40
41
42
43
# File 'lib/acts_as_paranoid/core.rb', line 37

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(paranoid_configuration[:deleted_value]).to_sql
  end
end

#string_type_with_deleted_value?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/acts_as_paranoid/core.rb', line 45

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