Module: Versions::Destroy
- Defined in:
- lib/versions/destroy.rb
Overview
If you include this module in your model (which should also include Versions::Multi), deleting the last version will destroy the model.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/versions/destroy.rb', line 5 def self.included(base) base.class_eval do before_destroy :check_can_destroy alias_method_chain :attributes=, :destroy end end |
Instance Method Details
#attributes_with_destroy=(hash) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/versions/destroy.rb', line 12 def attributes_with_destroy=(hash) if hash.delete(:__destroy) || hash.delete('__destroy') self.mark_for_destruction end self.attributes_without_destroy = hash end |