Sha256: 538cc6f1f1a768a443bcfa297202bab06ff1923a10cf212c76b83a5ed52009e1

Contents?: true

Size: 1.02 KB

Versions: 5

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

5 entries across 5 versions & 3 rubygems

Version Path
houston-vestal_versions-3.0.0 lib/vestal_versions/deletion.rb
houston-vestal_versions-2.0.1 lib/vestal_versions/deletion.rb
houston-vestal_versions-2.0.0 lib/vestal_versions/deletion.rb
vestal_versions-2.0.0 lib/vestal_versions/deletion.rb
mil_vestal_versions-1.2.6 lib/vestal_versions/deletion.rb