Sha256: a136e0bb9eac495453500a5e71061ceacee53326c5d9f8f04cf81d03b0dd7593

Contents?: true

Size: 626 Bytes

Versions: 7

Compression:

Stored size: 626 Bytes

Contents

# typed: true
# frozen_string_literal: true

module CleanArchitecture
  module Queries
    class HttpSuccessCode
      def initialize(http_method)
        @http_method = http_method
      end

      def to_sym
        code = HTTP_METHOD_TO_SUCCESS_CODE[@http_method.to_s.upcase]
        if code.nil?
          raise NotImplementedError, "cannot determine success code for HTTP method #{@http_method}"
        end

        code
      end

      private

      HTTP_METHOD_TO_SUCCESS_CODE = {
        'GET' => :ok,
        'POST' => :created,
        'PUT' => :accepted,
        'DELETE' => :ok
      }.freeze
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

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