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.
463 464 465 466 467 468 |
# File 'lib/wakame/service.rb', line 463 def initialize(service_cluster) @graph = Graph.new @graph.add_vertex(0) @service_cluster = service_cluster @nodes = {} end |
Instance Method Details
#add_object(obj) ⇒ Object
471 472 473 474 475 |
# File 'lib/wakame/service.rb', line 471 def add_object(obj) @nodes[obj.hash] = obj @graph.add_edge(0, obj.hash) self end |
#children(obj) ⇒ Object
500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/wakame/service.rb', line 500 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
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/wakame/service.rb', line 532 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
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
# File 'lib/wakame/service.rb', line 512 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
488 489 490 491 492 493 494 495 496 497 498 |
# File 'lib/wakame/service.rb', line 488 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
477 478 479 480 481 482 |
# File 'lib/wakame/service.rb', line 477 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
484 485 486 |
# File 'lib/wakame/service.rb', line 484 def size @graph.size - 1 end |