Module: Caboose::Acts::Paranoid::ClassMethods

Defined in:
lib/caboose/acts/paranoid.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_paranoid(options = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/caboose/acts/paranoid.rb', line 52

def acts_as_paranoid(options = {})
  unless paranoid? # don't let AR call this twice
    class << self
      VALID_FIND_OPTIONS << :with_deleted unless VALID_FIND_OPTIONS.include?(:with_deleted)
    end
    ActiveRecord::Calculations::CALCULATIONS_OPTIONS << :with_deleted unless ActiveRecord::Calculations::CALCULATIONS_OPTIONS.include?(:with_deleted)
    cattr_accessor :deleted_attribute
    self.deleted_attribute = options[:with] || :deleted_at
    alias_method :destroy_without_callbacks!, :destroy_without_callbacks
    class << self
      alias_method :find_every_with_deleted,    :find_every
      alias_method :calculate_with_deleted,     :calculate
      alias_method :delete_all!,                :delete_all
    end
    if ActiveRecord::Base.respond_to?(:named_scope)
      named_scope :with_deleted, lambda { |with_deleted| (with_deleted == true) ? { :with_deleted => true } : {} }
    end
  end
  include InstanceMethods
end

#paranoid?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/caboose/acts/paranoid.rb', line 73

def paranoid?
  self.included_modules.include?(InstanceMethods)
end