Sha256: 7c2992fed88cdffaf2efaa5eae9951ab1a8a5d86b642a0324808f9a3e0210b95
Contents?: true
Size: 1.34 KB
Versions: 3
Compression:
Stored size: 1.34 KB
Contents
# frozen_string_literal: true module Goldiloader class AutoIncludeContext attr_reader :models def initialize @models = [] end def self.register_models(models, included_associations = nil) auto_include_context = Goldiloader::AutoIncludeContext.new auto_include_context.register_models(models) Array.wrap(included_associations).each do |included_association| associations = if included_association.is_a?(Hash) included_association.keys else Array.wrap(included_association) end nested_associations = if included_association.is_a?(Hash) included_association else Hash.new([]) end associations.each do |association| nested_models = models.flat_map do |model| model.association(association).target end.compact register_models(nested_models, nested_associations[association]) end end end def register_models(models) Array.wrap(models).each do |model| model.auto_include_context = self self.models << model end self end alias_method :register_model, :register_models end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
goldiloader-3.0.2 | lib/goldiloader/auto_include_context.rb |
goldiloader-3.0.1 | lib/goldiloader/auto_include_context.rb |
goldiloader-3.0.0 | lib/goldiloader/auto_include_context.rb |