Class: PactBroker::Api::Decorators::CustomErrorProblemJsonDecorator

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

Instance Method Summary collapse

Constructor Details

#initialize(title:, type:, detail:, status:) ⇒ CustomErrorProblemJsonDecorator

Returns a new instance of CustomErrorProblemJsonDecorator.

Parameters:

  • title (Hash)

    a customizable set of options

  • type (Hash)

    a customizable set of options

  • detail (Hash)

    a customizable set of options

  • status (Hash)

    a customizable set of options

Options Hash (title:):

  • (String)

Options Hash (type:):

  • (String)

Options Hash (detail:):

  • (String)

Options Hash (status:):

  • HTTP (Integer)

    status code



12
13
14
15
16
17
# File 'lib/pact_broker/api/decorators/custom_error_problem_json_decorator.rb', line 12

def initialize(title:, type:, detail:, status: )
  @title = title
  @type = type
  @detail = detail
  @status = status
end

Instance Method Details

#to_hash(user_options: {}, **__other) ⇒ Hash

Returns:

  • (Hash)


20
21
22
23
24
25
26
27
# File 'lib/pact_broker/api/decorators/custom_error_problem_json_decorator.rb', line 20

def to_hash(user_options: {}, **__other)
  {
    "title" => @title,
    "type" => "#{user_options[:base_url]}/problem/#{@type}",
    "detail" => @detail,
    "status" => @status
  }
end

#to_json(*args, **kwargs) ⇒ String

Returns JSON.

Returns:

  • (String)

    JSON



30
31
32
# File 'lib/pact_broker/api/decorators/custom_error_problem_json_decorator.rb', line 30

def to_json(*args, **kwargs)
  to_hash(*args, **kwargs).to_json
end