Class: ClearLogic::Types

Inherits:
Object
  • Object
show all
Defined in:
lib/clear_logic/types.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, prefix: nil) ⇒ Types

Returns a new instance of Types.



11
12
13
14
# File 'lib/clear_logic/types.rb', line 11

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

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



5
6
7
# File 'lib/clear_logic/types.rb', line 5

def klass
  @klass
end

#prefixObject (readonly)

Returns the value of attribute prefix.



5
6
7
# File 'lib/clear_logic/types.rb', line 5

def prefix
  @prefix
end

Class Method Details

.register(*args) ⇒ Object



7
8
9
# File 'lib/clear_logic/types.rb', line 7

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

Instance Method Details

#defineObject



20
21
22
# File 'lib/clear_logic/types.rb', line 20

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

#klass_keyObject



24
25
26
# File 'lib/clear_logic/types.rb', line 24

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

#registerObject



16
17
18
# File 'lib/clear_logic/types.rb', line 16

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