Class: CurationConcerns::ClassifyConcern

Inherits:
Object
  • Object
show all
Includes:
ActiveAttr::Model
Defined in:
app/models/curation_concerns/classify_concern.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.to_class(type) ⇒ Class

Returns the model class.

Parameters:

  • [String] (Hash)

    a customizable set of options

Returns:

  • (Class)

    the model class



39
40
41
42
43
44
45
46
47
# File 'app/models/curation_concerns/classify_concern.rb', line 39

def self.to_class(type)
  # TODO: we may want to allow a different (or nil) namespace
  type.camelize.constantize
  # begin
  #   "::#{type.camelize}".constantize
  # rescue NameError
  #   "CurationConcerns::#{type}".constantize
  # end
end

Instance Method Details

#all_curation_concern_classesObject



13
14
15
# File 'app/models/curation_concerns/classify_concern.rb', line 13

def all_curation_concern_classes
  registered_curation_concern_types.sort.map { |c| self.class.to_class(c) }
end

#curation_concern_classObject



27
28
29
30
31
32
33
34
35
# File 'app/models/curation_concerns/classify_concern.rb', line 27

def curation_concern_class
  if possible_curation_concern_types.detect do |_name, class_name|
    class_name == curation_concern_type
  end
    self.class.to_class(curation_concern_type)
  else
    fail 'Invalid :curation_concern_type'
  end
end

#possible_curation_concern_typesObject



21
22
23
24
25
# File 'app/models/curation_concerns/classify_concern.rb', line 21

def possible_curation_concern_types
  registered_curation_concern_types.collect do |concern|
    [self.class.to_class(concern).human_readable_type, concern]
  end
end

#registered_curation_concern_typesObject



17
18
19
# File 'app/models/curation_concerns/classify_concern.rb', line 17

def registered_curation_concern_types
  CurationConcerns.config.registered_curation_concern_types
end