Class: Hyrax::QuickClassificationQuery

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/quick_classification_query.rb

Overview

Provides an enumerator of the Work classes the user is authorized to create.

Examples:

QuickClassificationQuery.new(user: current_user).to_a

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, models: Hyrax.config.registered_curation_concern_types, concern_name_normalizer: ->(str) { str.constantize }) ⇒ QuickClassificationQuery



17
18
19
20
21
22
23
# File 'app/services/hyrax/quick_classification_query.rb', line 17

def initialize(user,
               models: Hyrax.config.registered_curation_concern_types,
               concern_name_normalizer: ->(str) { str.constantize })
  @user = user
  @concern_name_normalizer = concern_name_normalizer
  @models = models
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



12
13
14
# File 'app/services/hyrax/quick_classification_query.rb', line 12

def user
  @user
end

Instance Method Details

#all?Boolean



30
31
32
# File 'app/services/hyrax/quick_classification_query.rb', line 30

def all?
  models == Hyrax.config.registered_curation_concern_types
end

#authorized_modelsArray Also known as: to_a



35
36
37
# File 'app/services/hyrax/quick_classification_query.rb', line 35

def authorized_models
  normalized_model_names.select { |klass| user.can?(:create, klass) }
end

#each(&block) ⇒ Object



25
26
27
# File 'app/services/hyrax/quick_classification_query.rb', line 25

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