module ABBYY::Cloud::Types

Constants

FilledArray

Gem-specific primitive types

Public Class Methods

register_type(klass, as: nil, constructor: :new) click to toggle source

Registers new coercible type

# File lib/abbyy/cloud/types.rb, line 8
def self.register_type(klass, as: nil, constructor: :new)
  type_name  = Inflecto.underscore(as || klass.name.split("::").last)
  definition = Dry::Types::Definition.new(klass).constructor do |value|
    case value
    when nil   then raise
    when klass then value
    else klass.send(constructor, value)
    end
  end

  Dry::Types.register type_name, definition
  Dry::Types.define_constants self, [type_name]
end