Class: Sprig::Reap::TsortableHash
- Inherits:
-
Hash
- Object
- Hash
- Sprig::Reap::TsortableHash
- Includes:
- TSort
- Defined in:
- lib/sprig/reap/tsortable_hash.rb
Instance Method Summary collapse
Instance Method Details
#resolve_circular_habtm_dependencies! ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sprig/reap/tsortable_hash.rb', line 11 def resolve_circular_habtm_dependencies! # When two models each have a `has_and_belongs_to_many` association pointing to the other, # it creates a circular dependency. Based on Sprig documentation, we only need to define # the association in one direction # (https://github.com/vigetlabs/sprig#has-and-belongs-to-many), so we delete one of them. self.each do |(model, dependencies)| model.reflect_on_all_associations(:has_and_belongs_to_many).each do |association| if dependencies.include?(association.klass) && self[association.klass].present? self[association.klass] = self[association.klass] - [model] end end end end |
#tsort_each_child(node, &block) ⇒ Object
7 8 9 |
# File 'lib/sprig/reap/tsortable_hash.rb', line 7 def tsort_each_child(node, &block) fetch(node).each(&block) end |