Sha256: 233b969aa84c149b461cae8ebc645b2a03355745da7003d4a9a0f939648ab991

Contents?: true

Size: 1.27 KB

Versions: 163

Compression:

Stored size: 1.27 KB

Contents

module Concurrent
  module Utility
    # @private
    module NativeInteger
      # http://stackoverflow.com/questions/535721/ruby-max-integer
      MIN_VALUE = -(2**(0.size * 8 - 2))
      MAX_VALUE = (2**(0.size * 8 - 2) - 1)

      def ensure_upper_bound(value)
        if value > MAX_VALUE
          raise RangeError.new("#{value} is greater than the maximum value of #{MAX_VALUE}")
        end
        value
      end

      def ensure_lower_bound(value)
        if value < MIN_VALUE
          raise RangeError.new("#{value} is less than the maximum value of #{MIN_VALUE}")
        end
        value
      end

      def ensure_integer(value)
        unless value.is_a?(Integer)
          raise ArgumentError.new("#{value} is not an Integer")
        end
        value
      end

      def ensure_integer_and_bounds(value)
        ensure_integer value
        ensure_upper_bound value
        ensure_lower_bound value
      end

      def ensure_positive(value)
        if value < 0
          raise ArgumentError.new("#{value} cannot be negative")
        end
        value
      end

      def ensure_positive_and_no_zero(value)
        if value < 1
          raise ArgumentError.new("#{value} cannot be negative or zero")
        end
        value
      end

      extend self
    end
  end
end

Version data entries

163 entries across 145 versions & 34 rubygems

Version Path
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_integer.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/native_integer.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_integer.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_integer.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_integer.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/native_integer.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_integer.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/native_integer.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_integer.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.4/lib/concurrent/utility/native_integer.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_integer.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/native_integer.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_integer.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_integer.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_integer.rb
concurrent-ruby-1.1.6 lib/concurrent-ruby/concurrent/utility/native_integer.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/native_integer.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/native_integer.rb
concurrent-ruby-1.1.6.pre1 lib/concurrent-ruby/concurrent/utility/native_integer.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/native_integer.rb