Module: Cms::Behaviors::SoftDeleting::MacroMethods

Defined in:
lib/cms/behaviors/soft_deleting.rb

Instance Method Summary collapse

Instance Method Details

#handle_missing_table_error_during_startup(message, e) ⇒ Object



13
14
15
# File 'lib/cms/behaviors/soft_deleting.rb', line 13

def handle_missing_table_error_during_startup(message, e)
  Rails.logger.debug "#{message}: #{e.inspect}"
end

#uses_soft_delete(options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cms/behaviors/soft_deleting.rb', line 17

def uses_soft_delete(options={})
  @uses_soft_delete = true

  scope :not_deleted, :conditions => ["#{table_name}.deleted = ?", false]
  class << self
    alias_method :delete_all!, :delete_all
  end

  extend ClassMethods
  include InstanceMethods
  attr_accessible :deleted

  # By default, all queries for blocks should filter out deleted rows.
  begin
    default_scope where(:deleted => false)
  # This may fail during gem loading, if no DB or the table does not exist. Log it and move on.
  rescue StandardError => e
    handle_missing_table_error_during_startup("Can't set a default_scope for soft_deleting", e)
  end
end

#uses_soft_delete?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/cms/behaviors/soft_deleting.rb', line 9

def uses_soft_delete?
  !!@uses_soft_delete
end