Class: DirtySeed::Sorter

Inherits:
Object
  • Object
show all
Defined in:
lib/dirty_seed/sorter.rb

Overview

Sorts ActiveRecord models depending on their associations

Instance Method Summary collapse

Constructor Details

#initialize(models = []) ⇒ DirtySeed::Sorter

Initializes an instance

Parameters:



9
10
11
# File 'lib/dirty_seed/sorter.rb', line 9

def initialize(models = [])
  @models = models
end

Instance Method Details

#sortArray<Class>

Note:

Use procedural over fonctional -> do not use recursivity

Sorts models depending on their associations

Returns:

  • (Array<Class>)

    classes inheriting from ActiveRecord::Base



16
17
18
19
20
21
22
23
24
# File 'lib/dirty_seed/sorter.rb', line 16

def sort
  reset
  until unsorted.empty?
    count_up || break
    self.current = unsorted.first
    sort_current
  end
  sorted
end