Class: CleanArchitecture::Serializers::HtmlResponseFromResult

Inherits:
Object
  • Object
show all
Defined in:
lib/clean_architecture/serializers/html_response_from_result.rb

Instance Method Summary collapse

Constructor Details

#initialize(result, http_method) ⇒ HtmlResponseFromResult

Returns a new instance of HtmlResponseFromResult.



9
10
11
12
# File 'lib/clean_architecture/serializers/html_response_from_result.rb', line 9

def initialize(result, http_method)
  @result = result
  @http_method = http_method
end

Instance Method Details

#to_hObject



14
15
16
17
18
19
20
21
# File 'lib/clean_architecture/serializers/html_response_from_result.rb', line 14

def to_h
  Dry::Matcher::ResultMatcher.call(@result) do |matcher|
    matcher.success do |data|
      { status: Queries::HttpSuccessCode.new(@http_method).to_sym, data: data }
    end
    matcher.failure { |error_message| { status: :error, error: error_message } }
  end
end