Class: ProblemDetails::Rails::RenderOptionBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/problem_details/rails/render_option_builder.rb

Overview

A builder to build a hash that is passed to ActionController’s render method.

Instance Method Summary collapse

Constructor Details

#initialize(content, options) ⇒ RenderOptionBuilder

Returns a new instance of RenderOptionBuilder.

Parameters:

  • content (Hash)

    given as a value of :problem key of render method.

  • options (Hash)

    options of render method.



9
10
11
12
# File 'lib/problem_details/rails/render_option_builder.rb', line 9

def initialize(content, options)
  @content = content
  @options = options.dup
end

Instance Method Details

#buildHash

Returns build a hash being passed to render method.

Returns:

  • (Hash)

    build a hash being passed to render method.



15
16
17
18
19
20
# File 'lib/problem_details/rails/render_option_builder.rb', line 15

def build
  content_type = @options.delete(:content_type) || ProblemDetails::Rails.config.default_json_content_type
  status = @options.delete(:status) || :ok
  document = ProblemDetails::Document.new(status: status, **@content)
  { json: document.to_h, status: status, content_type: content_type, **@options }
end