Sha256: 33ce00e4fc7550bbca553789a549fd65917b7ccae1ac01a6bd79ffde5207f3c6

Contents?: true

Size: 478 Bytes

Versions: 2

Compression:

Stored size: 478 Bytes

Contents

# frozen_string_literal: true

module ActiveRecordDataLoader
  module ActiveRecord
    class IntegerValueGenerator
      class << self
        def generator_for(model_class:, ar_column:, connection_factory: nil)
          range_limit = [(256**number_of_bytes(ar_column)) / 2 - 1, 1_000_000_000].min

          -> { rand(0..range_limit) }
        end

        private

        def number_of_bytes(ar_column)
          ar_column.limit || 8
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_record_data_loader-1.1.0 lib/active_record_data_loader/active_record/integer_value_generator.rb
active_record_data_loader-1.0.2 lib/active_record_data_loader/active_record/integer_value_generator.rb