Class: CurationConcerns::QuickClassificationQuery

Inherits:
Object
  • Object
show all
Defined in:
app/models/curation_concerns/quick_classification_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, options = {}) ⇒ QuickClassificationQuery

Returns a new instance of QuickClassificationQuery.

Parameters:

  • user (User)

    the current user

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :concern_name_normalizer (#call) — default: ClassifyConcern.to_class

    a proc that translates names to classes

  • :models (Array<String>)

    the options to display, defaults to everything.



9
10
11
12
13
# File 'app/models/curation_concerns/quick_classification_query.rb', line 9

def initialize(user, options = {})
  @user = user
  @concern_name_normalizer = options.fetch(:concern_name_normalizer, ClassifyConcern.method(:to_class))
  @models = options.fetch(:models, CurationConcerns.config.registered_curation_concern_types)
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



3
4
5
# File 'app/models/curation_concerns/quick_classification_query.rb', line 3

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



20
21
22
# File 'app/models/curation_concerns/quick_classification_query.rb', line 20

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

#authorized_modelsArray

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



25
26
27
# File 'app/models/curation_concerns/quick_classification_query.rb', line 25

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

#each(&block) ⇒ Object



15
16
17
# File 'app/models/curation_concerns/quick_classification_query.rb', line 15

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