Sha256: ba2910ae8cc5f878de495705b6f96fc997852ab3d4224056e8f08ceb71bd0198

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

require 'active_attr'
class ClassifyConcern
  # @TODO - This should be part of the application configuration
  # or detected on load
  VALID_CURATION_CONCERN_CLASS_NAMES = [
    'MockCurationConcern'
  ]
  include ActiveAttr::Model
  attribute :curation_concern_type

  validates(
    :curation_concern_type,
    presence: true,
    inclusion: { in: lambda { |record| VALID_CURATION_CONCERN_CLASS_NAMES } }
  )

  def self.all_curation_concern_classes
    VALID_CURATION_CONCERN_CLASS_NAMES.collect(&:constantize)
  end

  def all_curation_concern_classes
    self.class.all_curation_concern_classes
  end

  def possible_curation_concern_types
    VALID_CURATION_CONCERN_CLASS_NAMES.collect{|concern|
      [concern.constantize.human_readable_type, concern]
    }
  end

  def curation_concern_class
    if possible_curation_concern_types.detect{|name, class_name|
        class_name == curation_concern_type
      }
      curation_concern_type.constantize
    else
      raise RuntimeError, "Invalid :curation_concern_type"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
curate-0.3.2 app/models/classify_concern.rb
curate-0.3.1 app/models/classify_concern.rb
curate-0.2.0 app/models/classify_concern.rb