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.

Defined Under Namespace

Modules: Version

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



39
40
41
# File 'lib/versions/destroy.rb', line 39

def self.included(base)
  base.alias_method_chain :save, :destroy
end

Instance Method Details

#save_with_destroy(*args) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/versions/destroy.rb', line 43

def save_with_destroy(*args)
  version = self.version
  # TODO: we could use 'version.mark_for_destruction' instead of __destroy...
  if version.__destroy && versions.count == 1
    destroy # will destroy last version
  else
    save_without_destroy(*args)
  end
end