Class: PactBroker::Api::Decorators::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/api/decorators/configuration.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(overrides = {}) ⇒ Configuration

Returns a new instance of Configuration.



9
10
11
# File 'lib/pact_broker/api/decorators/configuration.rb', line 9

def initialize(overrides = {})
  @overrides = overrides
end

Class Method Details

.default_configurationObject



42
43
44
# File 'lib/pact_broker/api/decorators/configuration.rb', line 42

def self.default_configuration
  Configuration.new
end

Instance Method Details

#class_for(name) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/pact_broker/api/decorators/configuration.rb', line 13

def class_for(name)
  if overrides[name].is_a?(String)
    Object.const_get(overrides[name])
  elsif overrides[name].is_a?(Class)
    overrides[name]
  else
    Object.const_get("PactBroker::Api::Decorators::#{name.to_s.camelcase(true)}")
  end
end

#validation_error_decorator_class_for(errors_class, accept_header) ⇒ Class

Returns the decorator class.

Parameters:

  • errors_class (Class)

    will be a Hash class or Dry::Validation::MessageSet class

  • accept_header (String)

    if this includes application/problem+json we render a application/problem+json response

Returns:

  • (Class)

    the decorator class



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pact_broker/api/decorators/configuration.rb', line 26

def validation_error_decorator_class_for(errors_class, accept_header)
  if accept_header&.include?("application/problem+json")
    if errors_class == Dry::Validation::MessageSet
      PactBroker::Api::Decorators::DryValidationErrorsProblemJsonDecorator
    else
      PactBroker::Api::Decorators::ValidationErrorsProblemJsonDecorator
    end
  else
    if errors_class == Dry::Validation::MessageSet
      PactBroker::Api::Decorators::DryValidationErrorsDecorator
    else
      PactBroker::Api::Decorators::ValidationErrorsDecorator
    end
  end
end