Class: WeakSwaggerParameters::Services::WeakParametersOptionsAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/weak_swagger_parameters/services/weak_parameters_options_adapter.rb

Constant Summary collapse

MAX_VALUE =
(2**(0.size * 8 - 2) - 1)
MIN_VALUE =
- 2))

Class Method Summary collapse

Class Method Details

.adapt(options) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/weak_swagger_parameters/services/weak_parameters_options_adapter.rb', line 9

def self.adapt(options)
  result = {}
  result[:strong] = true
  result[:required] = options[:required]
  result[:only] = options[:enum] if options[:enum].present?
  result = result.merge(range_options(options))

  result
end

.range_options(options) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/weak_swagger_parameters/services/weak_parameters_options_adapter.rb', line 19

def self.range_options(options)
  return {} unless options.key?(:min) || options.key?(:max)

  max = options[:max] || MAX_VALUE
  min = options[:min] || MIN_VALUE
  { only: min...max }
end