Class: Seedie::Model::ModelSorter

Inherits:
Object
  • Object
show all
Includes:
PolymorphicAssociationHelper
Defined in:
lib/seedie/model/model_sorter.rb

Instance Method Summary collapse

Methods included from PolymorphicAssociationHelper

#find_polymorphic_types, #has_association?, #select_associations

Constructor Details

#initialize(models) ⇒ ModelSorter

Returns a new instance of ModelSorter.



8
9
10
11
12
13
# File 'lib/seedie/model/model_sorter.rb', line 8

def initialize(models)
  @models = models
  @model_dependencies = models.map { |m| [m, get_model_dependencies(m)] }.to_h
  @resolved_queue = []
  @unresolved = []
end

Instance Method Details

#sort_by_dependencyObject



15
16
17
18
19
20
21
22
23
# File 'lib/seedie/model/model_sorter.rb', line 15

def sort_by_dependency
  add_independent_models_to_queue

  @models.each do |model|
    resolve_dependencies(model) unless @resolved_queue.include?(model)
  end

  @resolved_queue
end