Sha256: 179230a4e23d09896daf38d66160ad4f214ed94581a5203e8bcffe513b917295
Contents?: true
Size: 1.02 KB
Versions: 19
Compression:
Stored size: 1.02 KB
Contents
module Finitio module Syntax module Contract include Node capture :type, :pair capture_str :contract_name 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, metadata) end 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 def to_ast ast = [ :contract, contract_name, (type && type.to_ast) ] ast << pair.to_ast if pair ast end end # module Contract end # module Syntax end # module Finitio
Version data entries
19 entries across 19 versions & 1 rubygems