Class: Spider::App::RuntimeSort

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeRuntimeSort

Returns a new instance of RuntimeSort.



605
606
607
608
# File 'lib/spiderfw/app.rb', line 605

def initialize
    @apps = []
    @apps_hash = {}
end

Instance Method Details

#add(app) ⇒ Object

Adds an app to be sorted

Parameters:

  • app (AppSpec|String)

    the app to add



613
614
615
616
617
618
619
620
# File 'lib/spiderfw/app.rb', line 613

def add(app)
    @apps << app
    if app.is_a?(AppSpec)
        @apps_hash[app.app_id] = app
    else
        @apps_hash[app] = app
    end
end

#tsortArray

Runs tsort

Returns:

  • (Array)

    an array of sorted App ids



638
639
640
641
# File 'lib/spiderfw/app.rb', line 638

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

Parameters:

  • node (AppSpec)

    the app to get dependecies for

  • block (Proc)


631
632
633
634
# File 'lib/spiderfw/app.rb', line 631

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

Parameters:

  • block (Proc)


624
625
626
# File 'lib/spiderfw/app.rb', line 624

def tsort_each_node(&block)
    @apps.each(&block)
end