Module: Pragma::Contract::Coercion::ClassMethods

Defined in:
lib/pragma/contract/coercion.rb

Instance Method Summary collapse

Instance Method Details

#build_type(namespace, type) ⇒ Object



41
42
43
# File 'lib/pragma/contract/coercion.rb', line 41

def build_type(namespace, type)
  Object.const_get "Pragma::Contract::Types::#{namespace}::#{type.to_s.capitalize}"
end

#coercible(type) ⇒ Object



15
16
17
# File 'lib/pragma/contract/coercion.rb', line 15

def coercible(type)
  build_type 'Coercible', type
end

#form(type) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/pragma/contract/coercion.rb', line 19

def form(type)
  # Dry::Types 0.13 renames Types::Form to Types::Params and the Int type to Integer.

  if Dry::Types['form.int']
    build_type 'Form', type
  else
    build_type 'Params', type.to_sym == :int ? :integer : type
  end
end

#json(type) ⇒ Object



29
30
31
# File 'lib/pragma/contract/coercion.rb', line 29

def json(type)
  build_type 'Json', type
end

#maybe_coercible(type) ⇒ Object



37
38
39
# File 'lib/pragma/contract/coercion.rb', line 37

def maybe_coercible(type)
  build_type 'Maybe::Coercible', type
end

#maybe_strict(type) ⇒ Object



33
34
35
# File 'lib/pragma/contract/coercion.rb', line 33

def maybe_strict(type)
  build_type 'Maybe::Strict', type
end

#strict(type) ⇒ Object



11
12
13
# File 'lib/pragma/contract/coercion.rb', line 11

def strict(type)
  build_type 'Strict', type
end