-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: default application context properties inside constructor so t…
…hat PF doesn't have to set each one explictly
- Loading branch information
Showing
1 changed file
with
29 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |