Sha256: 4bed69bdc98795a839679d8b102c4dac62448805be500cf709109edc3fc8274e
Contents?: true
Size: 1.27 KB
Versions: 9
Compression:
Stored size: 1.27 KB
Contents
require 'active_attr' module Worthwhile class ClassifyConcern include ActiveAttr::Model attribute :curation_concern_type validates( :curation_concern_type, presence: true, inclusion: { in: lambda { |record| record.registered_curation_concern_types } } ) def all_curation_concern_classes registered_curation_concern_types.sort.map { |c| self.class.to_class(c) } end def registered_curation_concern_types Worthwhile.configuration.registered_curation_concern_types end def possible_curation_concern_types registered_curation_concern_types.collect do |concern| [self.class.to_class(concern).human_readable_type, concern] end end def curation_concern_class if possible_curation_concern_types.detect{|name, class_name| class_name == curation_concern_type } self.class.to_class(curation_concern_type) else raise RuntimeError, "Invalid :curation_concern_type" end end 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 # "Worthwhile::#{type}".constantize # end end end end
Version data entries
9 entries across 9 versions & 2 rubygems