Sha256: 2e5d65adad210e85274be8bff91e758a289303c3b1537ddd8696e6cb3d80057e

Contents?: true

Size: 1.26 KB

Versions: 48

Compression:

Stored size: 1.26 KB

Contents

module Hyrax
  class QuickClassificationQuery
    attr_reader :user

    # @param [User] user the current user
    # @param [Hash] options
    # @option options [#call] :concern_name_normalizer (String#constantize) a proc that translates names to classes
    # @option options [Array<String>] :models the options to display, defaults to everything.
    def initialize(user, options = {})
      @user = user
      @concern_name_normalizer = options.fetch(:concern_name_normalizer, ->(str) { str.constantize })
      @models = options.fetch(:models, Hyrax.config.registered_curation_concern_types)
    end

    def each(&block)
      authorized_models.each(&block)
    end

    # @return true if the requested concerns is same as all avaliable concerns
    def all?
      models == Hyrax.config.registered_curation_concern_types
    end

    # @return [Array] a list of all the requested concerns that the user can create
    def authorized_models
      normalized_model_names.select { |klass| user.can?(:create, klass) }
    end

    private

      attr_reader :concern_name_normalizer, :models

      # Transform the list of requested model names into a list of class names
      def normalized_model_names
        models.map { |name| concern_name_normalizer.call(name) }
      end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
hyrax-2.9.6 app/services/hyrax/quick_classification_query.rb
hyrax-2.9.5 app/services/hyrax/quick_classification_query.rb
hyrax-2.9.4 app/services/hyrax/quick_classification_query.rb
hyrax-2.9.3 app/services/hyrax/quick_classification_query.rb
hyrax-2.9.2 app/services/hyrax/quick_classification_query.rb
hyrax-2.9.1 app/services/hyrax/quick_classification_query.rb
hyrax-2.9.0 app/services/hyrax/quick_classification_query.rb
hyrax-2.8.0 app/services/hyrax/quick_classification_query.rb
hyrax-2.7.2 app/services/hyrax/quick_classification_query.rb
hyrax-2.7.1 app/services/hyrax/quick_classification_query.rb
hyrax-2.7.0 app/services/hyrax/quick_classification_query.rb
hyrax-2.6.0 app/services/hyrax/quick_classification_query.rb
hyrax-3.0.0.pre.rc1 app/services/hyrax/quick_classification_query.rb
hyrax-3.0.0.pre.beta3 app/services/hyrax/quick_classification_query.rb
hyrax-2.5.1 app/services/hyrax/quick_classification_query.rb
hyrax-2.5.0 app/services/hyrax/quick_classification_query.rb
hyrax-3.0.0.pre.beta2 app/services/hyrax/quick_classification_query.rb
hyrax-2.4.1 app/services/hyrax/quick_classification_query.rb
hyrax-3.0.0.pre.beta1 app/services/hyrax/quick_classification_query.rb
hyrax-2.4.0 app/services/hyrax/quick_classification_query.rb