Module: Paranoia::Query

Defined in:
lib/paranoia.rb

Instance Method Summary collapse

Instance Method Details

#only_deletedObject Also known as: deleted



31
32
33
# File 'lib/paranoia.rb', line 31

def only_deleted
  with_deleted.where.not(paranoia_column => paranoia_sentinel_value)
end

#paranoid?Boolean

Returns:

  • (Boolean)


21
# File 'lib/paranoia.rb', line 21

def paranoid? ; true ; end

#restore(id_or_ids, opts = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/paranoia.rb', line 36

def restore(id_or_ids, opts = {})
  ids = Array(id_or_ids).flatten
  any_object_instead_of_id = ids.any? { |id| ActiveRecord::Base === id }
  if any_object_instead_of_id
    ids.map! { |id| ActiveRecord::Base === id ? id.id : id }
    ActiveSupport::Deprecation.warn("You are passing an instance of ActiveRecord::Base to `restore`. " \
                                    "Please pass the id of the object by calling `.id`")
  end
  ids.map { |id| only_deleted.find(id).restore!(opts) }
end

#with_deletedObject



23
24
25
26
27
28
29
# File 'lib/paranoia.rb', line 23

def with_deleted
  if ActiveRecord::VERSION::STRING >= "4.1"
    unscope where: paranoia_column
  else
    all.tap { |x| x.default_scoped = false }
  end
end