Module: ActiveRecord::Acts::Deactivatable::Definition

Defined in:
lib/deactivatable.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_deactivatable(options = {}) ⇒ Object

Define the calling class as being deactivatable.

A call to this will set the default scope of the object to look for deactivated_at = nil. Options

:dependencies - A list of symbols specifying any associations that are also deactivatable.  (The dependent association must separately be defined with acts_as_deactivatable).
:auto_configure_dependencies - true or false (default).  If set to true, any association defined as :dependent => :destroy or :dependent => :delete_all will be added to the list of dependencies to deactivate.  NOTE: This call must occur after your dependency definitions to work properly.


17
18
19
20
21
22
23
24
25
# File 'lib/deactivatable.rb', line 17

def acts_as_deactivatable(options={})
  extend ActiveRecord::Acts::Deactivatable::ClassMethods          
  include ActiveRecord::Acts::Deactivatable::InstanceMethods
            
  default_scope :conditions => {:deactivated_at => nil}
  
  @deactivatable_options = options
  setup_autoconfigured_dependencies if @deactivatable_options[:auto_configure_dependencies]
end