lib/pacto.rb in pacto-0.3.0.pre vs lib/pacto.rb in pacto-0.3.0
- old
+ new
@@ -1,75 +1,103 @@
require 'pacto/version'
-require 'httparty'
+require 'addressable/template'
+require 'middleware'
+require 'faraday'
require 'hash_deep_merge'
require 'multi_json'
require 'json-schema'
require 'json-generator'
require 'webmock'
require 'ostruct'
require 'erb'
require 'logger'
-require 'pacto/core/contract_repository'
-require 'pacto/core/configuration'
-require 'pacto/core/callback'
require 'pacto/logger'
+require 'pacto/ui'
+require 'pacto/core/contract_registry'
+require 'pacto/core/validation_registry'
+require 'pacto/core/configuration'
+require 'pacto/core/modes'
+require 'pacto/core/hook'
require 'pacto/exceptions/invalid_contract.rb'
require 'pacto/extensions'
-require 'pacto/request'
-require 'pacto/response_adapter'
-require 'pacto/response'
-require 'pacto/stubs/built_in'
+require 'pacto/request_clause'
+require 'pacto/response_clause'
+require 'pacto/stubs/webmock_adapter'
+require 'pacto/stubs/uri_pattern'
require 'pacto/contract'
+require 'pacto/contract_validator'
require 'pacto/contract_factory'
-require 'pacto/erb_processor'
-require 'pacto/hash_merge_processor'
-require 'pacto/stubs/built_in'
+require 'pacto/validation'
require 'pacto/meta_schema'
require 'pacto/hooks/erb_hook'
require 'pacto/generator'
+require 'pacto/generator/filters'
+require 'pacto/contract_files'
+require 'pacto/contract_list'
+require 'pacto/request_pattern'
+require 'pacto/uri'
+# Validators
+require 'pacto/validators/body_validator'
+require 'pacto/validators/request_body_validator'
+require 'pacto/validators/response_body_validator'
+require 'pacto/validators/response_status_validator'
+require 'pacto/validators/response_header_validator'
+
module Pacto
class << self
+ def contract_factory
+ @factory = ContractFactory.new
+ end
def configuration
@configuration ||= Configuration.new
end
+ def contract_registry
+ @registry ||= ContractRegistry.new
+ end
+
def clear!
Pacto.configuration.provider.reset!
+ @modes = nil
@configuration = nil
- unregister_all!
+ @registry = nil
+ Pacto::ValidationRegistry.instance.reset!
end
def configure
yield(configuration)
end
- end
- def self.validate_contract contract
- Pacto::MetaSchema.new.validate contract
- puts 'All contracts successfully meta-validated'
- true
- rescue InvalidContract => exception
- puts 'Validation errors detected'
- exception.errors.each do |error|
- puts " Error: #{error}"
+ def contracts_for(request_signature)
+ contract_registry.contracts_for(request_signature)
end
- false
- end
- def self.build_from_file(contract_path, host, file_pre_processor = Pacto.configuration.preprocessor)
- ContractFactory.build_from_file(contract_path, host, file_pre_processor)
- end
+ def validate_contract(contract)
+ Pacto::MetaSchema.new.validate contract
+ puts "Validating #{contract}"
+ true
+ rescue InvalidContract => exception
+ puts 'Validation errors detected'
+ exception.errors.each do |error|
+ puts " Error: #{error}"
+ end
+ false
+ end
- def self.load(contract_name)
- build_from_file(path_for(contract_name), nil)
- end
+ def load_contract(contract_path, host)
+ load_contracts(contract_path, host).contracts.first
+ end
- private
-
- def self.path_for(contract)
- File.join(configuration.contracts_path, "#{contract}.json")
+ def load_contracts(contracts_path, host)
+ files = ContractFiles.for(contracts_path)
+ contracts = contract_factory.build(files, host)
+ contracts.each do |contract|
+ contract_registry.register(contract)
+ end
+ ContractList.new(contracts)
+ end
end
end