Sha256: 8d289d43ee3ead58be8a2f7ffce61ce15090d7d68331524522118495c228ae60

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

module VestalVersions
  # Adds the ability to "reset" (or hard revert) a versioned ActiveRecord::Base instance.
  module Reset
    def self.included(base) # :nodoc:
      base.class_eval do
        include InstanceMethods
      end
    end

    # Adds the instance methods required to reset an object to a previous version.
    module InstanceMethods
      # Similar to +revert_to!+, the +reset_to!+ method reverts an object to a previous version,
      # only instead of creating a new record in the version history, +reset_to!+ deletes all of
      # the version history that occurs after the version reverted to.
      #
      # The action taken on each version record after the point of reversion is determined by the
      # <tt>:dependent</tt> option given to the +versioned+ method. See the +versioned+ method
      # documentation for more details.
      def reset_to!(value)
        if saved = skip_version{ revert_to!(value) }
          versions.send(:delete_records, versions.after(value))
          reset_version
        end
        saved
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 4 rubygems

Version Path
nickjones-vestal_versions-1.0.3 lib/vestal_versions/reset.rb
bitfluent-vestal_versions-1.1.0 lib/vestal_versions/reset.rb
brianjlandau-vestal_versions-1.3.0 lib/vestal_versions/reset.rb
vestal_versions-1.0.2 lib/vestal_versions/reset.rb