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.
12 13 14 |
# File 'lib/dendrite/service_graph.rb', line 12 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
16 17 18 19 20 |
# File 'lib/dendrite/service_graph.rb', line 16 def <<(service) raise KeyError unless service.name raise DuplicateService if services.keys.include?(service.name) services[service.name] = service end |
#[](name) ⇒ Object
22 23 24 |
# File 'lib/dendrite/service_graph.rb', line 22 def [](name) services.fetch(name) end |
#collisions ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/dendrite/service_graph.rb', line 26 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
35 36 37 38 39 |
# File 'lib/dendrite/service_graph.rb', line 35 def validate_nodes services.each do |name, service| errors.add(name, service.errors.) unless service.valid? end end |