Sha256: cd69f81743f59aa5fbb3354016c63e195d76b2dea1026cb46d6a91a8640f443b

Contents?: true

Size: 657 Bytes

Versions: 2

Compression:

Stored size: 657 Bytes

Contents

# frozen_string_literal: true

require 'dry/matcher/result_matcher'
require 'clean_architecture/queries/http_success_code'

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

      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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clean-architecture-0.1.0 lib/clean_architecture/serializers/html_response_from_result.rb
clean-architecture-0.0.5 lib/clean_architecture/serializers/html_response_from_result.rb