lib/pact/consumer/mock_service.rb in pact-mock_service-0.2.3 vs lib/pact/consumer/mock_service.rb in pact-mock_service-0.2.4

- old
+ new

@@ -1,2 +1,43 @@ require 'pact/consumer/mock_service/app' +require 'pact/consumer/mock_service/error_handler' +module Pact + module Consumer + + class MockService + + def initialize options = {} + logger, log_description = configure_logger(options) + app_options = options.merge(logger: logger, log_description: log_description) + @app = Rack::Builder.app do + use ErrorHandler, logger + use CorsOriginHeaderMiddleware, options[:cors_enabled] + run App.new(app_options) + end + end + + def call env + @app.call env + end + + def shutdown + @app.shutdown + end + + def configure_logger options + options = {log_file: $stdout}.merge options + log_stream = options[:log_file] + logger = Logger.new log_stream + logger.formatter = options[:log_formatter] if options[:log_formatter] + logger.level = Pact.configuration.logger.level + + log_description = if log_stream.is_a? File + File.absolute_path(log_stream).gsub(Dir.pwd + "/", '') + else + "standard out/err" + end + return logger, log_description + end + end + end +end