Class: Praxis::RequestStages::ValidateParamsAndHeaders
- Inherits:
-
RequestStage
- Object
- Stage
- RequestStage
- Praxis::RequestStages::ValidateParamsAndHeaders
- Defined in:
- lib/praxis/request_stages/validate_params_and_headers.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Attributes inherited from Stage
#after_callbacks, #before_callbacks, #context, #name, #stages
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(name, context, parent:) ⇒ ValidateParamsAndHeaders
constructor
A new instance of ValidateParamsAndHeaders.
- #path ⇒ Object
Methods inherited from RequestStage
#action, #controller, #execute_controller_callbacks, #execute_with_around, #request, #run, #setup!, #validation_handler
Methods inherited from Stage
#after, #application, #before, #callback_args, #execute_callbacks, #run, #setup!, #setup_deferred_callbacks!
Constructor Details
#initialize(name, context, parent:) ⇒ ValidateParamsAndHeaders
Returns a new instance of ValidateParamsAndHeaders.
7 8 9 10 |
# File 'lib/praxis/request_stages/validate_params_and_headers.rb', line 7 def initialize(name, context, parent:) super @parent = parent end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
5 6 7 |
# File 'lib/praxis/request_stages/validate_params_and_headers.rb', line 5 def parent @parent end |
Instance Method Details
#execute ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/praxis/request_stages/validate_params_and_headers.rb', line 16 def execute begin request.load_headers(CONTEXT_FOR[:headers]) rescue => e = "Error loading headers." return validation_handler.handle!( exception: e, summary: , request: request, stage: name ) end begin request.load_params(CONTEXT_FOR[:params]) rescue Attributor::AttributorException => e = "Error loading params." return validation_handler.handle!( exception: e, summary: , request: request, stage: name ) end attribute_resolver = Attributor::AttributeResolver.new Attributor::AttributeResolver.current = attribute_resolver attribute_resolver.register("headers",request.headers) attribute_resolver.register("params",request.params) errors = request.validate_headers(CONTEXT_FOR[:headers]) errors += request.validate_params(CONTEXT_FOR[:params]) if errors.any? = "Error validating request data." return validation_handler.handle!( summary: , errors: errors, request: request, stage: name ) end end |
#path ⇒ Object
12 13 14 |
# File 'lib/praxis/request_stages/validate_params_and_headers.rb', line 12 def path @_path ||= ( @parent.path + [name] ) end |