Class: Fitting::Request

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

Defined Under Namespace

Classes: NotDocumented, Unsuitable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env_request, tomogram) ⇒ Request

Returns a new instance of Request.

Raises:



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

def initialize(env_request, tomogram)
  @method = env_request.request_method
  @path = env_request.env['PATH_INFO']
  @body = env_request.env['action_dispatch.request.request_parameters']
  @schema = tomogram.find_request(method: @method, path: @path)
  raise NotDocumented unless @schema || Fitting.configuration.skip_not_documented
  self
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



3
4
5
# File 'lib/fitting/request.rb', line 3

def body
  @body
end

#methodObject

Returns the value of attribute method.



3
4
5
# File 'lib/fitting/request.rb', line 3

def method
  @method
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/fitting/request.rb', line 3

def path
  @path
end

#schemaObject

Returns the value of attribute schema.



3
4
5
# File 'lib/fitting/request.rb', line 3

def schema
  @schema
end

Instance Method Details

#to_hashObject



26
27
28
29
30
31
32
33
# File 'lib/fitting/request.rb', line 26

def to_hash
  {
    'method' => @method,
    'path' => @path,
    'body' => @body,
    'schema' => @schema
  }
end

#valid!Object

Raises:



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

def valid!
  res = JSON::Validator.fully_validate(@schema['request'], @body)
  raise Unsuitable unless res.empty?
end

#validate?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/fitting/request.rb', line 22

def validate?
  @schema && Fitting.configuration.validation_requests
end