Class: Meta::Parameters
- Inherits:
-
Object
- Object
- Meta::Parameters
- Extended by:
- Forwardable
- Defined in:
- lib/meta/application/parameters.rb
Instance Attribute Summary collapse
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Instance Method Summary collapse
- #filter(request) ⇒ Object
-
#initialize(parameters) ⇒ Parameters
constructor
A new instance of Parameters.
- #merge(parameters) ⇒ Object
- #to_swagger_doc ⇒ Object
Constructor Details
#initialize(parameters) ⇒ Parameters
Returns a new instance of Parameters.
9 10 11 |
# File 'lib/meta/application/parameters.rb', line 9 def initialize(parameters) @parameters = parameters.dup end |
Instance Attribute Details
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
7 8 9 |
# File 'lib/meta/application/parameters.rb', line 7 def parameters @parameters end |
Instance Method Details
#filter(request) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/meta/application/parameters.rb', line 13 def filter(request) errors = {} final_value = {} parameters.each do |name, | schema = [:schema] value = if [:in] == 'header' schema.filter(request.get_header('HTTP_' + name.to_s.upcase.gsub('-', '_'))) else schema.filter(request.params[name.to_s]) end final_value[name] = value rescue JsonSchema::ValidationError => e errors[name] = e. end raise Errors::ParameterInvalid.new(errors) unless errors.empty? final_value end |
#merge(parameters) ⇒ Object
48 49 50 51 |
# File 'lib/meta/application/parameters.rb', line 48 def merge(parameters) parameters_hash = parameters.is_a?(Parameters) ? parameters.parameters : parameters Parameters.new(self.parameters.merge(parameters_hash)) end |
#to_swagger_doc ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/meta/application/parameters.rb', line 33 def to_swagger_doc parameters.map do |name, | = [:schema]. { name: name, in: [:in], required: .key?(:required) ? [:required] : false, description: [:description] || '', schema: { type: [:type] }.compact }.compact end unless parameters.empty? end |