Sha256: 0a44685ba7bba93453d9125710fe88530d0ecf89458485eb23329ad09bb31a08

Contents?: true

Size: 602 Bytes

Versions: 3

Compression:

Stored size: 602 Bytes

Contents

# frozen_string_literal: true

require 'dry/matcher/result_matcher'

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

3 entries across 3 versions & 1 rubygems

Version Path
clean-architecture-0.0.4 lib/clean_architecture/serializers/html_response_from_result.rb
clean-architecture-0.0.3 lib/clean_architecture/serializers/html_response_from_result.rb
clean-architecture-0.0.1 lib/clean_architecture/serializers/html_response_from_result.rb