Sha256: e76d529de38c7f9b7c5fbf7c4928042cde452c3bb03deabdab3ecc147710b58a

Contents?: true

Size: 864 Bytes

Versions: 1

Compression:

Stored size: 864 Bytes

Contents

module Qrb
  module Syntax
    module Contract

      def compile(factory, clazz)
        contract = [ type.compile(factory) ] + compile_pair(factory, clazz)
        { contract_name.to_sym => contract }
      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
          [ Qrb::IDENTITY, Qrb::IDENTITY ]
        end
      end

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

    end # module Contract
  end # module Syntax
end # module Qrb

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qrb-0.3.0 lib/qrb/syntax/contract.rb