Skip to content

Commit

Permalink
chore: default application context properties inside constructor so t…
Browse files Browse the repository at this point in the history
…hat PF doesn't have to set each one explictly
  • Loading branch information
bethesque committed Jan 12, 2021
1 parent b94b51c commit 1378222
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions lib/pact_broker/application_context.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
require 'pact_broker/api/decorators/configuration'
require 'pact_broker/api/decorators/decorator_context_creator'
require 'pact_broker/webhooks/execution_configuration_creator'
require 'pact_broker/errors/error_logger'
require 'pact_broker/api/resources/error_response_body_generator'

module PactBroker
class ApplicationContext
attr_reader :decorator_configuration, :decorator_context_creator, :webhook_execution_configuration_creator,
:resource_authorizer,
:before_resource,
:after_resource,
:error_logger,
:error_response_body_generator
attr_reader :decorator_configuration,
:decorator_context_creator,
:webhook_execution_configuration_creator,
:resource_authorizer,
:before_resource,
:after_resource,
:error_logger,
:error_response_body_generator

def initialize(params = {})
@decorator_configuration = params[:decorator_configuration]
@decorator_context_creator = params[:decorator_context_creator]
@webhook_execution_configuration_creator = params[:webhook_execution_configuration_creator]
@resource_authorizer = params[:resource_authorizer]
@before_resource = params[:before_resource]
@after_resource = params[:after_resource]
@error_logger = params[:error_logger]
@error_response_body_generator = params[:error_response_body_generator]
end

def self.default_application_context(overrides = {})
require 'pact_broker/api/decorators/configuration'
require 'pact_broker/api/decorators/decorator_context_creator'
require 'pact_broker/webhooks/execution_configuration_creator'
require 'pact_broker/errors/error_logger'
require 'pact_broker/api/resources/error_response_body_generator'

defaults = {
params_with_defaults = {
decorator_configuration: PactBroker::Api::Decorators::Configuration.default_configuration,
decorator_context_creator: PactBroker::Api::Decorators::DecoratorContextCreator,
webhook_execution_configuration_creator: PactBroker::Webhooks::ExecutionConfigurationCreator,
error_logger: PactBroker::Errors::ErrorLogger,
error_response_body_generator: PactBroker::Api::Resources::ErrorResponseBodyGenerator
}
ApplicationContext.new(defaults.merge(overrides))
}.merge(params)

@decorator_configuration = params_with_defaults[:decorator_configuration]
@decorator_context_creator = params_with_defaults[:decorator_context_creator]
@webhook_execution_configuration_creator = params_with_defaults[:webhook_execution_configuration_creator]
@resource_authorizer = params_with_defaults[:resource_authorizer]
@before_resource = params_with_defaults[:before_resource]
@after_resource = params_with_defaults[:after_resource]
@error_logger = params_with_defaults[:error_logger]
@error_response_body_generator = params_with_defaults[:error_response_body_generator]
end

def self.default_application_context(overrides = {})
ApplicationContext.new(overrides)
end
end
end

0 comments on commit 1378222

Please sign in to comment.