Module: ActsAsParanoid::ClassMethods

Defined in:
lib/rails3_acts_as_paranoid.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



52
53
54
# File 'lib/rails3_acts_as_paranoid.rb', line 52

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

Instance Method Details

#after_recover(method) ⇒ Object



60
61
62
# File 'lib/rails3_acts_as_paranoid.rb', line 60

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

#before_recover(method) ⇒ Object



56
57
58
# File 'lib/rails3_acts_as_paranoid.rb', line 56

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

#delete_all(conditions = nil) ⇒ Object



76
77
78
# File 'lib/rails3_acts_as_paranoid.rb', line 76

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

#delete_all!(conditions = nil) ⇒ Object



72
73
74
# File 'lib/rails3_acts_as_paranoid.rb', line 72

def delete_all!(conditions = nil)
  self.unscoped.delete_all!(conditions)
end

#delete_now_valueObject



92
93
94
95
96
97
98
# File 'lib/rails3_acts_as_paranoid.rb', line 92

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



88
89
90
# File 'lib/rails3_acts_as_paranoid.rb', line 88

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

#only_deletedObject



68
69
70
# File 'lib/rails3_acts_as_paranoid.rb', line 68

def only_deleted
  self.unscoped.where("#{paranoid_column_reference} IS NOT ?", nil)
end

#paranoid_columnObject



80
81
82
# File 'lib/rails3_acts_as_paranoid.rb', line 80

def paranoid_column
  paranoid_configuration[:column].to_sym
end

#paranoid_column_typeObject



84
85
86
# File 'lib/rails3_acts_as_paranoid.rb', line 84

def paranoid_column_type
  paranoid_configuration[:column_type].to_sym
end

#with_deletedObject



64
65
66
# File 'lib/rails3_acts_as_paranoid.rb', line 64

def with_deleted
  self.unscoped
end