Sha256: ad4940bc408d2193bd3c57e5b0fac6c241c71ec112b1f8a9e56d9c911c684039

Contents?: true

Size: 1.44 KB

Versions: 6

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true
module Hyrax
  ##
  # @abstract Propagates visibility from a provided object (e.g. a Work) to some
  #   group of its members (e.g. file_sets).
  class VisibilityPropagator
    ##
    # @param source [#visibility] the object to propagate visibility from
    #
    # @return [#propagate]
    def self.for(source:)
      case source
      when Hyrax::WorkBehavior # ActiveFedora
        FileSetVisibilityPropagator.new(source: source)
      when Hyrax::Resource # Valkyrie
        ResourceVisibilityPropagator.new(source: source)
      else
        NullVisibilityPropagator.new(source: source)
      end
    end

    ##
    # Provides a null/logging implementation of the visibility propagator.
    class NullVisibilityPropagator
      ##
      # @!attribute [rw] source
      #   @return [#visibility]
      attr_accessor :source

      ##
      # @param source [#visibility] the object to propagate visibility from
      def initialize(source:)
        self.source = source
      end

      ##
      # @return [void]
      # @raise [RuntimeError] if we're in development mode
      def propagate
        message =  "Tried to propagate visibility to members of #{source} " \
                   "but didn't know what kind of object it is. Model " \
                   "name #{source.try(:model_name)}. Called from #{caller[0]}."

        Hyrax.logger.warn(message)
        Rails.env.development? ? raise(message) : :noop
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hyrax-3.6.0 app/services/hyrax/visibility_propagator.rb
hyrax-4.0.0 app/services/hyrax/visibility_propagator.rb
hyrax-4.0.0.rc3 app/services/hyrax/visibility_propagator.rb
hyrax-4.0.0.rc2 app/services/hyrax/visibility_propagator.rb
hyrax-4.0.0.rc1 app/services/hyrax/visibility_propagator.rb
hyrax-3.5.0 app/services/hyrax/visibility_propagator.rb