Class: Dendrite::ServiceGraph
- Inherits:
-
Object
- Object
- Dendrite::ServiceGraph
- Extended by:
- Forwardable
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/dendrite/service_graph.rb
Instance Attribute Summary collapse
-
#services ⇒ Object
readonly
Returns the value of attribute services.
Instance Method Summary collapse
- #<<(service) ⇒ Object
- #[](name) ⇒ Object
- #collisions ⇒ Object
-
#initialize ⇒ ServiceGraph
constructor
A new instance of ServiceGraph.
- #validate_nodes ⇒ Object
Constructor Details
#initialize ⇒ ServiceGraph
Returns a new instance of ServiceGraph.
14 15 16 |
# File 'lib/dendrite/service_graph.rb', line 14 def initialize @services = {} end |
Instance Attribute Details
#services ⇒ Object (readonly)
Returns the value of attribute services.
6 7 8 |
# File 'lib/dendrite/service_graph.rb', line 6 def services @services end |
Instance Method Details
#<<(service) ⇒ Object
18 19 20 21 22 |
# File 'lib/dendrite/service_graph.rb', line 18 def <<(service) raise KeyError unless service.name raise DuplicateService, service.name if services.keys.include?(service.name) services[service.name] = service end |
#[](name) ⇒ Object
24 25 26 |
# File 'lib/dendrite/service_graph.rb', line 24 def [](name) services.fetch(name) end |
#collisions ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/dendrite/service_graph.rb', line 28 def collisions services.values.group_by(&:loadbalancer_port) .reject {|port, svc| port == nil} .select {|port, svc| svc.length > 1} .each do |port, svc| errors.add("port_collisions_#{port}", "collision between #{svc.collect(&:name).join(',')}") end end |
#validate_nodes ⇒ Object
37 38 39 40 41 |
# File 'lib/dendrite/service_graph.rb', line 37 def validate_nodes services.each do |name, service| errors.add(name, service.errors.) unless service.valid? end end |