Class: Fitting::Request
- Inherits:
-
Object
- Object
- Fitting::Request
- Defined in:
- lib/fitting/request.rb
Defined Under Namespace
Classes: NotDocumented, Unsuitable
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#method ⇒ Object
Returns the value of attribute method.
-
#path ⇒ Object
Returns the value of attribute path.
-
#schema ⇒ Object
Returns the value of attribute schema.
Instance Method Summary collapse
-
#initialize(env_request, tomogram) ⇒ Request
constructor
A new instance of Request.
- #to_hash ⇒ Object
- #valid! ⇒ Object
- #validate? ⇒ Boolean
Constructor Details
#initialize(env_request, tomogram) ⇒ Request
Returns a new instance of Request.
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
#body ⇒ Object
Returns the value of attribute body.
3 4 5 |
# File 'lib/fitting/request.rb', line 3 def body @body end |
#method ⇒ Object
Returns the value of attribute method.
3 4 5 |
# File 'lib/fitting/request.rb', line 3 def method @method end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/fitting/request.rb', line 3 def path @path end |
#schema ⇒ Object
Returns the value of attribute schema.
3 4 5 |
# File 'lib/fitting/request.rb', line 3 def schema @schema end |
Instance Method Details
#to_hash ⇒ Object
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
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
22 23 24 |
# File 'lib/fitting/request.rb', line 22 def validate? @schema && Fitting.configuration.validation_requests end |