Sha256: d07d9ce44319e1eb5be02b694032a670bda8595a429bcf2654a604c02172de78

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

module VestalVersions
  # Allows version creation to occur conditionally based on given <tt>:if</tt> and/or
  # <tt>:unless</tt> options.
  module Deletion
    extend ActiveSupport::Concern

    included do
      before_destroy :create_destroyed_version, :if => :delete_version?
    end

    # Class methods on ActiveRecord::Base
    module ClassMethods
      # After the original +prepare_versioned_options+ method cleans the given options, this alias
      # also extracts the <tt>:depedent</tt> if it set to <tt>:tracking</tt>
      def prepare_versioned_options(options)
        result = super(options)
        if result[:dependent] == :tracking
          self.vestal_versions_options[:track_destroy] = true
          options.delete(:dependent)
        end

        result
      end
    end

    private

    def delete_version?
      vestal_versions_options[:track_destroy]
    end

    def create_destroyed_version
      create_version({:modifications => attributes, :number => last_version + 1, :tag => 'deleted'})
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
geothird_vestal_versions-1.2.5 lib/vestal_versions/deletion.rb
geothird_vestal_versions-1.2.4 lib/vestal_versions/deletion.rb
geothird_vestal_versions-1.2.3 lib/vestal_versions/deletion.rb