Sha256: 2a82c98d012aaf0bc0ac4648f5470a071d09d7fbdebaf6436b5527386ff404c6

Contents?: true

Size: 922 Bytes

Versions: 8

Compression:

Stored size: 922 Bytes

Contents

class Evil::Client
  #
  # Resolves a http_method for the request from operation settings and schema
  # @private
  #
  class Resolver::HttpMethod < Resolver
    private

    def initialize(schema, settings)
      super schema, settings, :http_method
    end

    def __call__
      super do
        value = instance_exec(&__blocks__.last)&.to_s&.upcase if __blocks__.any?
        raise __not_defined_error__    if value.to_s == ""
        raise __invalid_error__(value) unless LIST.include? value
        value
      end
    end

    def __not_defined_error__
      __definition_error__ "HTTP method not defined"
    end

    def __invalid_error__(value)
      __definition_error__ "Unknown HTTP method #{value}"
    end

    # @see https://tools.ietf.org/html/rfc7231#section-4
    # @see https://tools.ietf.org/html/rfc5789#section-2
    LIST = %w[GET POST PUT PATCH DELETE OPTIONS HEAD TRACE CONNECT].freeze
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
evil-client-3.0.2 lib/evil/client/resolver/http_method.rb
evil-client-3.0.1 lib/evil/client/resolver/http_method.rb
evil-client-3.0.0 lib/evil/client/resolver/http_method.rb
evil-client-2.1.1 lib/evil/client/resolver/http_method.rb
evil-client-2.1.0 lib/evil/client/resolver/http_method.rb
evil-client-2.0.0 lib/evil/client/resolver/http_method.rb
evil-client-1.1.0 lib/evil/client/resolver/http_method.rb
evil-client-1.0.0 lib/evil/client/resolver/http_method.rb