Sha256: f507a7b3d12cc9d538bfca70ae017802718e5d96271745c661ed144fcc7d3a49

Contents?: true

Size: 721 Bytes

Versions: 2

Compression:

Stored size: 721 Bytes

Contents

# frozen_string_literal: true

module WeakSwaggerParameters
  module Services
    class WeakParametersOptionsAdapter
      MAX_VALUE = (2**(0.size * 8 - 2) - 1)
      MIN_VALUE = -(2**(0.size * 8 - 2))

      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

      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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
weak_swagger_parameters-0.6.0 lib/weak_swagger_parameters/services/weak_parameters_options_adapter.rb
weak_swagger_parameters-0.5.0 lib/weak_swagger_parameters/services/weak_parameters_options_adapter.rb