Class: ExcADG::VTracker
- Inherits:
-
Object
- Object
- ExcADG::VTracker
- Defined in:
- lib/excadg/vtracker.rb
Overview
tracker for Vertex-es graph: it’s hooked by Broker to register dependencies polling (and other) events and make an actual graph of vertices with states in runtime
it’s not possible to do this in other way, because vertices can be spawned:
-
in any order => code is not guaranteed to know the full graph (even static one)
-
dynamically => there is no central place but Broker that’s aware of all vertices
Instance Attribute Summary collapse
-
#by_state ⇒ Object
readonly
Returns the value of attribute by_state.
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
Instance Method Summary collapse
-
#get_deps(vertex) ⇒ Object
get all vertex’s dependencies.
-
#initialize ⇒ VTracker
constructor
A new instance of VTracker.
-
#track(vertex, deps = []) ⇒ Object
register the vertex and its new known deps in the @graph and by_state cache.
Constructor Details
#initialize ⇒ VTracker
Returns a new instance of VTracker.
16 17 18 19 |
# File 'lib/excadg/vtracker.rb', line 16 def initialize @graph = RGL::DirectedAdjacencyGraph.new @by_state = {} end |
Instance Attribute Details
#by_state ⇒ Object (readonly)
Returns the value of attribute by_state.
14 15 16 |
# File 'lib/excadg/vtracker.rb', line 14 def by_state @by_state end |
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
14 15 16 |
# File 'lib/excadg/vtracker.rb', line 14 def graph @graph end |
Instance Method Details
#get_deps(vertex) ⇒ Object
get all vertex’s dependencies
43 44 45 |
# File 'lib/excadg/vtracker.rb', line 43 def get_deps vertex @graph.adjacent_vertices vertex end |
#track(vertex, deps = []) ⇒ Object
register the vertex and its new known deps in the @graph and by_state cache
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/excadg/vtracker.rb', line 24 def track vertex, deps = [] Assertions.is_a? vertex, Vertex Assertions.is_a? deps, Array @graph.add_vertex vertex add_to_states_cache vertex, vertex.state deps.each { |raw_dep| # it could be not a Vertex, so do a lookup through data store next unless Broker.instance.data_store[raw_dep] dep_data = Broker.instance.data_store[raw_dep] add_to_states_cache dep_data.vertex, dep_data.state @graph.add_edge vertex, dep_data.vertex } end |