Module: SearchCraft::DependsOn::ClassMethods
- Included in:
- Builder, SearchCraft::DependsOn
- Defined in:
- lib/searchcraft/depends_on.rb
Constant Summary collapse
- @@dependencies =
{}
Instance Method Summary collapse
- #depends_on(*builder_names) ⇒ Object
- #sort_builders_by_dependency ⇒ Object
- #visit(builder, visited, sorted) ⇒ Object
Instance Method Details
#depends_on(*builder_names) ⇒ Object
5 6 7 |
# File 'lib/searchcraft/depends_on.rb', line 5 def depends_on(*builder_names) @@dependencies[name] = builder_names end |
#sort_builders_by_dependency ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/searchcraft/depends_on.rb', line 9 def sort_builders_by_dependency sorted = [] visited = {} builders_to_rebuild.each do |builder| visit(builder, visited, sorted) end sorted end |
#visit(builder, visited, sorted) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/searchcraft/depends_on.rb', line 20 def visit(builder, visited, sorted) return if visited[builder.name.to_s] dependency_names = @@dependencies[builder.name] || [] dependency_names.each do |dependency_name| dependency = Object.const_get(dependency_name) visit(dependency, visited, sorted) end visited[builder.name.to_s] = true sorted << builder end |