Module: Platanus::ActivableBase
- Defined in:
- lib/platanus/activable.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#is_active? ⇒ Boolean
Returns true if object hasnt been removed.
-
#remove! ⇒ Object
Deactivates a single record.
Class Method Details
.included(base) ⇒ Object
9 10 11 12 13 |
# File 'lib/platanus/activable.rb', line 9 def self.included(base) base.define_callbacks :remove base.attr_protected :removed_at base.extend ClassMethods end |
Instance Method Details
#is_active? ⇒ Boolean
Returns true if object hasnt been removed.
36 37 38 |
# File 'lib/platanus/activable.rb', line 36 def is_active? self.removed_at.nil? end |
#remove! ⇒ Object
Deactivates a single record.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/platanus/activable.rb', line 41 def remove! self.transaction do run_callbacks :remove do notify_observers :before_remove # Retrieve dependant properties and remove them. self.class.reflect_on_all_associations.select do |assoc| if assoc.[:dependent] == :destroy collection = self.send(assoc.name) collection.remove_all if collection.respond_to? :remove_all end end # Use update column to prevent update callbacks from being ran. self.update_column(:removed_at, DateTime.now) notify_observers :after_remove end end end |