Class: DirtySeed::Sorter
- Inherits:
-
Object
- Object
- DirtySeed::Sorter
- Defined in:
- lib/dirty_seed/sorter.rb
Overview
Sorts ActiveRecord models depending on their associations
Instance Method Summary collapse
-
#initialize(models = []) ⇒ DirtySeed::Sorter
constructor
Initializes an instance.
-
#sort ⇒ Array<Class>
Sorts models depending on their associations.
Constructor Details
#initialize(models = []) ⇒ DirtySeed::Sorter
Initializes an instance
9 10 11 |
# File 'lib/dirty_seed/sorter.rb', line 9 def initialize(models = []) @models = models end |
Instance Method Details
#sort ⇒ Array<Class>
Note:
Use procedural over fonctional -> do not use recursivity
Sorts models depending on their associations
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 |