Module: Paranoid::ParanoidMethods::ClassMethods

Defined in:
lib/paranoid/paranoid_methods.rb

Instance Method Summary collapse

Instance Method Details

#disable_paranoidObject

Temporarily disables paranoid on the model



29
30
31
32
33
34
35
36
37
38
# File 'lib/paranoid/paranoid_methods.rb', line 29

def disable_paranoid
  if block_given?
    @paranoid = false
    yield
  else
    raise 'Only block form is supported'
  end
ensure
  @paranoid = true
end

#paranoid_conditionObject

Returns the condition used to scope the return to exclude soft deleted records



13
14
15
# File 'lib/paranoid/paranoid_methods.rb', line 13

def paranoid_condition
  {destroyed_field => field_not_destroyed}
end

#paranoid_only_conditionObject

Returns the condition used to scope the return to contain only soft deleted records



19
20
21
22
23
24
25
26
# File 'lib/paranoid/paranoid_methods.rb', line 19

def paranoid_only_condition
  val = field_not_destroyed.respond_to?(:call) ? field_not_destroyed.call : field_not_destroyed
  column_sql = arel_table[destroyed_field].to_sql
  case val
  when nil then "#{column_sql} IS NOT NULL"
  else          ["#{column_sql} != ?", val]
  end
end