Class: DirtySeed::Sorter
- Inherits:
-
Object
- Object
- DirtySeed::Sorter
- Defined in:
- lib/dirty_seed/sorter.rb
Overview
Sorts ActiveRecord models depending on their associations
Instance Attribute Summary collapse
-
#checked ⇒ Object
readonly
Returns the value of attribute checked.
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#models ⇒ Object
(also: #unsorted)
readonly
Returns the value of attribute models.
-
#skip_optional ⇒ Object
readonly
Returns the value of attribute skip_optional.
-
#sorted ⇒ Object
readonly
Returns the value of attribute sorted.
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
12 13 14 15 16 17 |
# File 'lib/dirty_seed/sorter.rb', line 12 def initialize(models = []) @models = models @sorted = [] @checked = [] @current = unsorted.first end |
Instance Attribute Details
#checked ⇒ Object (readonly)
Returns the value of attribute checked.
6 7 8 |
# File 'lib/dirty_seed/sorter.rb', line 6 def checked @checked end |
#current ⇒ Object (readonly)
Returns the value of attribute current.
6 7 8 |
# File 'lib/dirty_seed/sorter.rb', line 6 def current @current end |
#models ⇒ Object (readonly) Also known as: unsorted
Returns the value of attribute models.
6 7 8 |
# File 'lib/dirty_seed/sorter.rb', line 6 def models @models end |
#skip_optional ⇒ Object (readonly)
Returns the value of attribute skip_optional.
6 7 8 |
# File 'lib/dirty_seed/sorter.rb', line 6 def skip_optional @skip_optional end |
#sorted ⇒ Object (readonly)
Returns the value of attribute sorted.
6 7 8 |
# File 'lib/dirty_seed/sorter.rb', line 6 def sorted @sorted end |
Instance Method Details
#sort! ⇒ Array<Class>
Sorts models depending on their associations
21 22 23 24 25 26 27 28 29 |
# File 'lib/dirty_seed/sorter.rb', line 21 def sort! return sorted if unsorted.empty? set_current # active skip_optional option to prevent infinite loop skip_optional! if break_loop? insert_or_rotate sort! end |