Sha256: 7381d24007d37770cd3df218ed2e1d8c6cf6d2737a59da6df489768ef5de1acb
Contents?: true
Size: 515 Bytes
Versions: 2
Compression:
Stored size: 515 Bytes
Contents
# frozen_string_literal: true module ActiveRecordDataLoader module Dsl class PolymorphicAssociation attr_reader :model_class, :name, :models def initialize(model_class, name) @model_class = model_class @name = name @models = {} end def model(klass, weight: 1) @models[klass] = weight.to_i end def weighted_models gcd = models.values.reduce(:gcd) models.map { |m, w| [m] * (w / gcd) }.flatten end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_record_data_loader-0.1.2 | lib/active_record_data_loader/dsl/polymorphic_association.rb |
active_record_data_loader-0.1.1 | lib/active_record_data_loader/dsl/polymorphic_association.rb |