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



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

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

Instance Method Details

#after_recover(method) ⇒ Object



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

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

#before_recover(method) ⇒ Object



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

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

#delete_all(conditions = nil) ⇒ Object



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

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

#delete_all!(conditions = nil) ⇒ Object



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

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

#delete_now_valueObject



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

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



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

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

#only_deletedObject



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

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

#paranoid_columnObject



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

def paranoid_column
  paranoid_configuration[:column].to_sym
end

#paranoid_column_typeObject



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

def paranoid_column_type
  paranoid_configuration[:column_type].to_sym
end

#with_deletedObject



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

def with_deleted
  self.unscoped
end