Sha256: b6a0b65d1956d9b70922a577971cf6ebba6bd05c1e44f49a7a91aa0258e3f4bf

Contents?: true

Size: 873 Bytes

Versions: 4

Compression:

Stored size: 873 Bytes

Contents

require 'json-schema'

module Fitting
  class Request
    def initialize(env_request, tomogram)
      @method = env_request.request_method
      @path = env_request.env['PATH_INFO'] || env_request.fullpath
      @body = env_request.env['action_dispatch.request.request_parameters']
      @schema = tomogram.find_request(method: @method, path: @path)
    end

    def route
      "#{@schema.method}\t#{@schema.path}"
    end

    def real_method_with_path
      "#{@method}\t#{@path}"
    end

    def schemas_of_possible_responses(status:)
      return nil unless @schema

      @schema.find_responses(status: status).map do |response|
        response['body']
      end
    end

    def within_prefix?(prefix)
      @path.start_with?(prefix)
    end

    def ignored?(ignore_list)
      ignore_list.any? do |regexp|
        regexp.match(@path)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fitting-2.18.3 lib/fitting/request.rb
fitting-2.18.2 lib/fitting/request.rb
fitting-2.18.1 lib/fitting/request.rb
fitting-2.18.0 lib/fitting/request.rb