Class: MinimumTerm::Service
- Inherits:
-
Object
- Object
- MinimumTerm::Service
- Defined in:
- lib/minimum-term/service.rb
Overview
Models a service and its published objects as well as consumed objects. The app itself is part of an Infrastructure
Instance Attribute Summary collapse
-
#consume ⇒ Object
readonly
Returns the value of attribute consume.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#infrastructure ⇒ Object
readonly
Returns the value of attribute infrastructure.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#publish ⇒ Object
readonly
Returns the value of attribute publish.
Instance Method Summary collapse
- #consumed_objects(publisher = nil) ⇒ Object
- #consumers ⇒ Object
- #consuming_from ⇒ Object
-
#initialize(infrastructure, data_dir) ⇒ Service
constructor
A new instance of Service.
- #published_objects ⇒ Object
- #satisfies?(service) ⇒ Boolean
- #satisfies_consumers?(verbose: false) ⇒ Boolean
Constructor Details
#initialize(infrastructure, data_dir) ⇒ Service
Returns a new instance of Service.
9 10 11 12 13 14 |
# File 'lib/minimum-term/service.rb', line 9 def initialize(infrastructure, data_dir) @infrastructure = infrastructure @data_dir = data_dir @name = File.basename(data_dir).underscore load_contracts end |
Instance Attribute Details
#consume ⇒ Object (readonly)
Returns the value of attribute consume.
7 8 9 |
# File 'lib/minimum-term/service.rb', line 7 def consume @consume end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/minimum-term/service.rb', line 7 def errors @errors end |
#infrastructure ⇒ Object (readonly)
Returns the value of attribute infrastructure.
7 8 9 |
# File 'lib/minimum-term/service.rb', line 7 def infrastructure @infrastructure end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/minimum-term/service.rb', line 7 def name @name end |
#publish ⇒ Object (readonly)
Returns the value of attribute publish.
7 8 9 |
# File 'lib/minimum-term/service.rb', line 7 def publish @publish end |
Instance Method Details
#consumed_objects(publisher = nil) ⇒ Object
26 27 28 29 30 |
# File 'lib/minimum-term/service.rb', line 26 def consumed_objects(publisher = nil) @consume.objects.select do |o| publisher.blank? or o.publisher == publisher end end |
#consumers ⇒ Object
20 21 22 23 24 |
# File 'lib/minimum-term/service.rb', line 20 def consumers infrastructure.services.values.select do |service| service.consuming_from.include?(self) end end |
#consuming_from ⇒ Object
16 17 18 |
# File 'lib/minimum-term/service.rb', line 16 def consuming_from consumed_objects.map(&:publisher).uniq end |
#published_objects ⇒ Object
32 33 34 |
# File 'lib/minimum-term/service.rb', line 32 def published_objects @publish.objects end |
#satisfies?(service) ⇒ Boolean
36 37 38 |
# File 'lib/minimum-term/service.rb', line 36 def satisfies?(service) @publish.satisfies?(service) end |
#satisfies_consumers?(verbose: false) ⇒ Boolean
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/minimum-term/service.rb', line 40 def satisfies_consumers?(verbose: false) @errors = {} print "#{name.camelize} satisfies: " if verbose consumers.each do |consumer| @publish.satisfies?(consumer) if @publish.errors.empty? print "#{consumer.name.camelize}".green if verbose next end print "#{consumer.name.camelize}".red if verbose @errors["#{name} -> #{consumer.name}"] = @publish.errors end print "\n" if verbose @errors.empty? end |