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

Returns a new instance of QuickClassificationQuery.

Parameters:

  • user (::User)

    the current user

  • concern_name_normalizer (#call) (defaults to: ->(str) { str.constantize })

    (String#constantize) a proc that translates names to classes

  • models (Array<String>) (defaults to: Hyrax.config.registered_curation_concern_types)

    the options to display, defaults to everything.


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

Returns true if the requested concerns is same as all avaliable concerns.

Returns:

  • (Boolean)

    true if the requested concerns is same as all avaliable concerns


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

Returns a list of all the requested concerns that the user can create.

Returns:

  • (Array)

    a list of all the requested concerns that the user can create


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