Sha256: 7170ddbc14d015f401e6a0b45fe5f928d8523d54522c8abcd29c8a4525b00bf4

Contents?: true

Size: 536 Bytes

Versions: 1

Compression:

Stored size: 536 Bytes

Contents

# frozen_string_literal: true

module ClearLogic
  class Types
    attr_reader :klass, :prefix

    def self.register(*args)
      new(*args).register
    end

    def initialize(klass, prefix: nil)
      @klass = klass
      @prefix = prefix
    end

    def register
      Dry::Types.register(klass_key, define)
    end

    def define
      Dry::Types::Nominal.new(klass).constrained(type: klass)
    end

    def klass_key
      [prefix, Dry::Inflector.new.underscore(klass.name).gsub('/', '.')].compact.join('.')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clear_logic-0.1.1 lib/clear_logic/types.rb