class ProblemDetails::Rails::RenderOptionBuilder

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

Public Class Methods

new(content, options) click to toggle source

@param [Hash] content given as a value of :problem key of render method. @param [Hash] options options of render method.

# File lib/problem_details/rails/render_option_builder.rb, line 9
def initialize(content, options)
  @content = content
  @options = options.dup
end

Public Instance Methods

build() click to toggle source

@return [Hash] build a hash being passed to render method.

# 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