Class: Spider::App::RuntimeSort
- Includes:
- TSort
- Defined in:
- lib/spiderfw/app.rb
Overview
Helper class to sort the runtime dependencies of an app using TSort.
Instance Method Summary collapse
-
#add(app) ⇒ Object
Adds an app to be sorted.
-
#initialize ⇒ RuntimeSort
constructor
A new instance of RuntimeSort.
-
#tsort ⇒ Array
Runs tsort.
-
#tsort_each_child(node, &block) ⇒ Object
Runs the given block for each dependency of node.
-
#tsort_each_node(&block) ⇒ Object
Runs block on each dependency.
Constructor Details
#initialize ⇒ RuntimeSort
Returns a new instance of RuntimeSort.
617 618 619 620 |
# File 'lib/spiderfw/app.rb', line 617 def initialize @apps = [] @apps_hash = {} end |
Instance Method Details
#add(app) ⇒ Object
Adds an app to be sorted
625 626 627 628 629 630 631 632 |
# File 'lib/spiderfw/app.rb', line 625 def add(app) @apps << app if app.is_a?(AppSpec) @apps_hash[app.app_id] = app else @apps_hash[app] = app end end |
#tsort ⇒ Array
Runs tsort
650 651 652 653 |
# File 'lib/spiderfw/app.rb', line 650 def tsort sorted = super sorted.map{ |a| a.is_a?(AppSpec) ? a.app_id : a } end |
#tsort_each_child(node, &block) ⇒ Object
Runs the given block for each dependency of node
643 644 645 646 |
# File 'lib/spiderfw/app.rb', line 643 def tsort_each_child(node, &block) return unless node.is_a?(AppSpec) node.get_runtime_dependencies.map{ |a| @apps_hash[a] }.each(&block) end |
#tsort_each_node(&block) ⇒ Object
Runs block on each dependency
636 637 638 |
# File 'lib/spiderfw/app.rb', line 636 def tsort_each_node(&block) @apps.each(&block) end |