nwjsmith/thumbtack

View on GitHub
lib/thumbtack/types/integer.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

module Thumbtack
  module Types
    # Handles validation of Integer types as the values supported by Pinboard
    #
    # @api private
    class Integer < Identity
      # The minimum allowable integer
      MIN = 0
      # The maximum allowable integer
      MAX = 2**32

      # Validate something is a valid integer parameter
      #
      # @param [Integer] value
      #   the integer to validate
      #
      # @return [self]
      #
      # @raise [Types::ValidationError]
      #   if the value is not between 0 and 2^32
      def self.validate(value)
        RangeValidation.validate value, MIN..MAX
        self
      end
    end
  end
end