Sha256: ee511a9fcf51014220677a5eb74bb402fd83586604b48c0bf34e26358798b7a4

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

# -*- encoding : utf-8 -*-
module Pacto
  class ContractFactory
    include Singleton
    include Logger

    def initialize
      @factories = {}
    end

    def add_factory(format, factory)
      @factories[format.to_sym] = factory
    end

    def remove_factory(format)
      @factories.delete format
    end

    def build(contract_files, host, format = :legacy)
      factory = @factories[format.to_sym]
      fail "No Contract factory registered for #{format}" if factory.nil?

      contract_files.map { |file| factory.build_from_file(file, host) }.flatten
    end

    def load_contracts(contracts_path, host, format = :legacy)
      factory = @factories[format.to_sym]
      files = factory.files_for(contracts_path)
      contracts = ContractFactory.build(files, host, format)
      contracts
    end

    class << self
      extend Forwardable
      def_delegators :instance, *ContractFactory.instance_methods(false)
    end
  end
end

require 'pacto/formats/legacy/contract_factory'
require 'pacto/formats/swagger/contract_factory'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pacto-0.4.0.rc3 lib/pacto/contract_factory.rb
pacto-0.4.0.rc2 lib/pacto/contract_factory.rb