Sha256: 84feb0386098dda4e860c502092cd7b44e112103edd77ba1d481fe705a1dd2d2

Contents?: true

Size: 1.18 KB

Versions: 27

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true
module Hyrax
  ##
  # Applies a `VisibilityIntention` to a repository object.
  class VisibilityIntentionApplicator
    ##
    # @!attribute [rw] intention
    #   @return [VisibilityIntention]
    attr_accessor :intention

    ##
    # @param [VisibilityIntention] intention
    def initialize(intention:)
      self.intention = intention
    end

    ##
    # @param [VisibilityIntention] intention
    #
    # @return [VisibilityIntentionApplicator]
    def self.apply(intention)
      new(intention: intention)
    end

    ##
    # @param [Object] model an object; this probably needs to be leasable,
    #   embargoable, has visibility, and an AdminSet/PermissionTemplate.
    def apply_to(model:)
      if intention.wants_embargo?
        raise InvalidIntentionError unless intention.valid_embargo?
        model.apply_embargo(*intention.embargo_params)
      elsif intention.wants_lease?
        raise InvalidIntentionError unless intention.valid_lease?
        model.apply_lease(*intention.lease_params)
      else
        model.visibility = intention.visibility
      end
    end
    alias to apply_to

    class InvalidIntentionError < ArgumentError; end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/services/hyrax/visibility_intention_applicator.rb
hyrax-5.0.0 app/services/hyrax/visibility_intention_applicator.rb
hyrax-5.0.0.rc3 app/services/hyrax/visibility_intention_applicator.rb
hyrax-5.0.0.rc2 app/services/hyrax/visibility_intention_applicator.rb
hyrax-5.0.0.rc1 app/services/hyrax/visibility_intention_applicator.rb
hyrax-3.6.0 app/services/hyrax/visibility_intention_applicator.rb
hyrax-4.0.0 app/services/hyrax/visibility_intention_applicator.rb
hyrax-4.0.0.rc3 app/services/hyrax/visibility_intention_applicator.rb
hyrax-4.0.0.rc2 app/services/hyrax/visibility_intention_applicator.rb
hyrax-4.0.0.rc1 app/services/hyrax/visibility_intention_applicator.rb
hyrax-3.5.0 app/services/hyrax/visibility_intention_applicator.rb
hyrax-4.0.0.beta2 app/services/hyrax/visibility_intention_applicator.rb
hyrax-3.4.2 app/services/hyrax/visibility_intention_applicator.rb
hyrax-4.0.0.beta1 app/services/hyrax/visibility_intention_applicator.rb
hyrax-3.4.1 app/services/hyrax/visibility_intention_applicator.rb
hyrax-3.4.0 app/services/hyrax/visibility_intention_applicator.rb
hyrax-3.3.0 app/services/hyrax/visibility_intention_applicator.rb
hyrax-3.2.0 app/services/hyrax/visibility_intention_applicator.rb
hyrax-3.1.0 app/services/hyrax/visibility_intention_applicator.rb
hyrax-3.0.2 app/services/hyrax/visibility_intention_applicator.rb