Sha256: e24e116903f1b2e30c622992cdd1d354efc5a48ed309fb3dcc780dbbeafd976c

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

# 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-2.0.0 lib/clean_architecture/serializers/html_response_from_result.rb
clean-architecture-1.2.0 lib/clean_architecture/serializers/html_response_from_result.rb
clean-architecture-1.1.1 lib/clean_architecture/serializers/html_response_from_result.rb
clean-architecture-1.1.0 lib/clean_architecture/serializers/html_response_from_result.rb
clean-architecture-1.0.1 lib/clean_architecture/serializers/html_response_from_result.rb
clean-architecture-1.0.0 lib/clean_architecture/serializers/html_response_from_result.rb
clean-architecture-0.2.0 lib/clean_architecture/serializers/html_response_from_result.rb