Class: Wakame::Service::DependencyGraph
- Inherits:
-
Object
- Object
- Wakame::Service::DependencyGraph
- Defined in:
- lib/wakame/service.rb
Instance Method Summary collapse
- #add_object(obj) ⇒ Object
- #children(obj) ⇒ Object
- #each_level(root = nil, &blk) ⇒ Object
-
#initialize(service_cluster) ⇒ DependencyGraph
constructor
A new instance of DependencyGraph.
- #levels(root = nil) ⇒ Object
- #parents(obj) ⇒ Object
- #set_dependency(parent_obj, child_obj) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(service_cluster) ⇒ DependencyGraph
Returns a new instance of DependencyGraph.
361 362 363 364 365 366 |
# File 'lib/wakame/service.rb', line 361 def initialize(service_cluster) @graph = Graph.new @graph.add_vertex(0) @service_cluster = service_cluster @nodes = {} end |
Instance Method Details
#add_object(obj) ⇒ Object
369 370 371 372 373 |
# File 'lib/wakame/service.rb', line 369 def add_object(obj) @nodes[obj.hash] = obj @graph.add_edge(0, obj.hash) self end |
#children(obj) ⇒ Object
398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/wakame/service.rb', line 398 def children(obj) obj = case obj when Class obj.to_s.hash when String obj.hash else raise ArgumentError end @graph.children(obj).collect { |hashid| property_obj(hashid) } end |
#each_level(root = nil, &blk) ⇒ Object
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
# File 'lib/wakame/service.rb', line 430 def each_level(root=nil, &blk) root = case root when nil 0 when Class root.to_s.hash when String root.hash else raise ArgumentError end @graph.level_layout(root).each { |l| l.each { |hashid| next if hashid == 0 blk.call(@service_cluster.properties[@nodes[hashid]]) } } end |
#levels(root = nil) ⇒ Object
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/wakame/service.rb', line 410 def levels(root=nil) root = case root when nil 0 when Class root.to_s.hash when String root.hash else raise ArgumentError end n=[] @graph.level_layout(root).each { |l| next if l.size == 1 && l[0] == 0 n << l.collect { |hashid| property_obj(hashid)} #n << l.collect { |hashid| @nodes[hashid].to_s } } n end |
#parents(obj) ⇒ Object
386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/wakame/service.rb', line 386 def parents(obj) obj = case obj when Class obj.to_s.hash when String obj.hash else raise ArgumentError end @graph.parents(obj).collect { |hashid| property_obj(hashid) } end |
#set_dependency(parent_obj, child_obj) ⇒ Object
375 376 377 378 379 380 |
# File 'lib/wakame/service.rb', line 375 def set_dependency(parent_obj, child_obj) return if parent_obj == child_obj @graph.add_edge(parent_obj.hash, child_obj.hash) @graph.remove_edge(0, child_obj.hash) if @graph.has_edge?(0, child_obj.hash) self end |
#size ⇒ Object
382 383 384 |
# File 'lib/wakame/service.rb', line 382 def size @graph.size - 1 end |