Module: Finitio::Syntax::Contract

Includes:
Node
Defined in:
lib/finitio/syntax/type/contract.rb

Instance Method Summary collapse

Methods included from Node

included, #metadata, #resolve_ruby_const, #unique_names!

Instance Method Details

#compile(factory, clazz) ⇒ Object



9
10
11
12
13
14
# File 'lib/finitio/syntax/type/contract.rb', line 9

def compile(factory, clazz)
  name = contract_name.to_sym
  infotype = type.compile(factory)
  dresser, undresser  = compile_pair(factory, clazz)
  factory.contract(infotype, dresser, undresser, name, )
end

#compile_pair(factory, clazz) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/finitio/syntax/type/contract.rb', line 16

def compile_pair(factory, clazz)
  if pair
    pair.compile(factory)
  elsif clazz
    dresser   = clazz.method(contract_name.to_sym)
    undresser = clazz.instance_method(:"to_#{contract_name}")
    [
      dresser,
      ->(d){ undresser.bind(d).call }
    ]
  else
    [ Finitio::IDENTITY, Finitio::IDENTITY ]
  end
end

#to_astObject



31
32
33
34
35
36
37
38
39
# File 'lib/finitio/syntax/type/contract.rb', line 31

def to_ast
  ast = [
    :contract,
    contract_name,
    (type && type.to_ast) 
  ]
  ast << pair.to_ast if pair
  ast
end