Sha256: 1465d8fd55339f247f560badab6b0d09487b5715135e63b547a859fbabf4b77b

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

# typed: true
# frozen_string_literal: true

require 'clean_architecture/entities/failure_details'
require 'clean_architecture/matchers/use_case_result'
require 'clean_architecture/queries/http_success_code'
require 'clean_architecture/queries/http_failure_code'

module CleanArchitecture
  module Serializers
    class HtmlResponseFromResult
      def initialize(result, http_method)
        @result = result
        @http_method = http_method
      end

      def to_h
        Matchers::UseCaseResult.call(@result) do |matcher|
          matcher.success { |data| success_html_response(data) }
          matcher.failure { |failure_details| failure_html_response(failure_details) }
        end
      end

      private

      def success_html_response(data)
        { status: Queries::HttpSuccessCode.new(@http_method).to_sym, data: data }
      end

      def failure_html_response(failure_details)
        status = Queries::HttpFailureCode.new(failure_details.type).to_sym
        { status: status, error: failure_details.message }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
clean-architecture-5.0.2 lib/clean_architecture/serializers/html_response_from_result.rb
clean-architecture-5.0.1 lib/clean_architecture/serializers/html_response_from_result.rb
clean-architecture-4.0.1 lib/clean_architecture/serializers/html_response_from_result.rb
clean-architecture-4.0.0 lib/clean_architecture/serializers/html_response_from_result.rb
clean-architecture-3.0.2 lib/clean_architecture/serializers/html_response_from_result.rb
clean-architecture-3.0.1 lib/clean_architecture/serializers/html_response_from_result.rb
clean-architecture-3.0.0 lib/clean_architecture/serializers/html_response_from_result.rb