Module: Valkyrie::Types

Defined in:
lib/valkyrie/types.rb

Overview

Namespace for Dry::Types types.

Constant Summary collapse

ID =

Valkyrie::ID

Dry::Types::Definition
     .new(Valkyrie::ID)
     .constructor do |input|
  if input.respond_to?(:each)
    # Solr::ORMConverter tries to pass an array of Valkyrie::IDs
    Valkyrie::ID.new(input.first)
  else
    Valkyrie::ID.new(input)
  end
end
URI =

Valkyrie::URI

Dry::Types::Definition
      .new(RDF::URI)
      .constructor do |input|
  if input.present?
    RDF::URI.new(input.to_s)
  else
    input
  end
end
Anything =

Used for casting Resources if possible.

Valkyrie::Types::Any.constructor do |value|
  if value.respond_to?(:fetch) && value.fetch(:internal_resource, nil)
    value.fetch(:internal_resource).constantize.new(value)
  else
    value
  end
end
Set =

Represents an array of unique values.

Valkyrie::Types::Coercible::Array.constructor do |value|
  value.select(&:present?).uniq.map do |val|
    Anything[val]
  end
end.default([].freeze)
Array =
Dry::Types['coercible.array'].default([].freeze)
SingleValuedString =

Used for when an input may be an array, but the output needs to be a single string.

Valkyrie::Types::String.constructor do |value|
  ::Array.wrap(value).first.to_s
end