Sha256: 3e984858175ad79881317b811b5043a5809c1d0e88119ddcef5a76b05ff1e869

Contents?: true

Size: 1.01 KB

Versions: 9

Compression:

Stored size: 1.01 KB

Contents

module Hyrax
  module Actors
    # Validates that the submitted version is the most recent version in the datastore.
    # Caveat: we are not detecting if the version is changed by a different process between
    # the time this validator is run and when the object is saved
    class OptimisticLockValidator < Actors::AbstractActor
      class_attribute :version_field
      self.version_field = 'version'

      def update(attributes)
        validate_lock(version_attribute(attributes)) && next_actor.update(attributes)
      end

      private

        # @return [Boolean] returns true if the lock is missing or
        #                   if it matches the current object version.
        def validate_lock(version)
          return true if version.blank? || version == curation_concern.etag
          curation_concern.errors.add(:base, :conflict)
          false
        end

        # Removes the version attribute
        def version_attribute(attributes)
          attributes.delete(version_field)
        end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hyrax-1.1.1 app/actors/hyrax/actors/optimistic_lock_validator.rb
hyrax-1.1.0 app/actors/hyrax/actors/optimistic_lock_validator.rb
hyrax-1.0.5 app/actors/hyrax/actors/optimistic_lock_validator.rb
hyrax-1.0.4 app/actors/hyrax/actors/optimistic_lock_validator.rb
hyrax-1.0.3 app/actors/hyrax/actors/optimistic_lock_validator.rb
hyrax-1.0.2 app/actors/hyrax/actors/optimistic_lock_validator.rb
hyrax-1.0.1 app/actors/hyrax/actors/optimistic_lock_validator.rb
hyrax-1.0.0.rc2 app/actors/hyrax/actors/optimistic_lock_validator.rb
hyrax-1.0.0.rc1 app/actors/hyrax/actors/optimistic_lock_validator.rb