Class: Crystal::Processors::PrepareParams

Inherits:
Crystal::Processor show all
Defined in:
lib/crystal/http/processors/prepare_params.rb

Instance Attribute Summary

Attributes inherited from Crystal::Processor

#next_processor

Instance Method Summary collapse

Methods inherited from Crystal::Processor

#initialize, inspect

Constructor Details

This class inherits a constructor from Crystal::Processor

Instance Method Details

#callObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/crystal/http/processors/prepare_params.rb', line 4

def call
  workspace.env.must_be.defined

  workspace.request = Crystal::Request.new(workspace.env)
  workspace.path = workspace.request.path
  params = workspace.params = Crystal::Params.new(workspace.request.params)

  if params.json?
    json_params = JSON.load params['json']
    json_params.must_be.a Hash
    json_params.keys.each do |k|
      logger.warn "Parameter :#{k} will be overwriden from JSON!" if params.include?(k)
    end
    params.merge! json_params
  end
  
  next_processor.call
end