Sha256: 76521366b81debbed1ce0597b046052ed869677110df65051160bf26c9012b41
Contents?: true
Size: 596 Bytes
Versions: 4
Compression:
Stored size: 596 Bytes
Contents
# frozen_string_literal: true module ActiveRecordDataLoader module ActiveRecord class EnumValueGenerator class << self def generator_for(model_class:, ar_column:) values = enum_values_for(model_class, ar_column.sql_type) -> { values.sample } end private def enum_values_for(model_class, enum_type) model_class .connection .execute("SELECT unnest(enum_range(NULL::#{enum_type}))::text") .map(&:values) .flatten .compact end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems