Class: MinimumTerm::Service

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#consumeObject (readonly)

Returns the value of attribute consume.



7
8
9
# File 'lib/minimum-term/service.rb', line 7

def consume
  @consume
end

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/minimum-term/service.rb', line 7

def errors
  @errors
end

#infrastructureObject (readonly)

Returns the value of attribute infrastructure.



7
8
9
# File 'lib/minimum-term/service.rb', line 7

def infrastructure
  @infrastructure
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/minimum-term/service.rb', line 7

def name
  @name
end

#publishObject (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

#consumersObject



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_fromObject



16
17
18
# File 'lib/minimum-term/service.rb', line 16

def consuming_from
  consumed_objects.map(&:publisher).uniq
end

#published_objectsObject



32
33
34
# File 'lib/minimum-term/service.rb', line 32

def published_objects
  @publish.objects
end

#satisfies?(service) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/minimum-term/service.rb', line 36

def satisfies?(service)
  @publish.satisfies?(service)
end

#satisfies_consumers?(verbose: false) ⇒ Boolean

Returns:

  • (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