Class: Fitting::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/fitting/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(env_request, tomogram) ⇒ Request

Returns a new instance of Request.



5
6
7
8
9
10
11
12
13
14
# File 'lib/fitting/request.rb', line 5

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)
  @fully_validate = JSON::Validator.fully_validate(@schema.request, @body) if @schema
  @valid = false
  @valid = true if @fully_validate == []
  self
end

Instance Method Details

#real_method_with_pathObject



20
21
22
# File 'lib/fitting/request.rb', line 20

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

#routeObject



16
17
18
# File 'lib/fitting/request.rb', line 16

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

#schemas_of_possible_responses(status:) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/fitting/request.rb', line 24

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