class Lacerda::Service

Models a service and its published objects as well as consumed objects. The app itself is part of an Infrastructure

Attributes

consume[R]
errors[R]
infrastructure[R]
name[R]
publish[R]

Public Class Methods

new(infrastructure, data_dir) click to toggle source
# File lib/lacerda/service.rb, line 12
def initialize(infrastructure, data_dir)
  @infrastructure = infrastructure
  @data_dir = data_dir
  @name = File.basename(data_dir).underscore
  load_contracts
end

Public Instance Methods

consume_object(type, data) click to toggle source
# File lib/lacerda/service.rb, line 102
def consume_object(type, data)
  object_description = @consume.object(type)
  Blumquist.new(schema: object_description.schema, data: data)
end
consume_object_from(service_name, type, data) click to toggle source
# File lib/lacerda/service.rb, line 98
def consume_object_from(service_name, type, data)
  consume_object([service_name, type].join(Lacerda::SCOPE_SEPARATOR), data)
end
consumed_objects(publisher = nil) click to toggle source
# File lib/lacerda/service.rb, line 29
def consumed_objects(publisher = nil)
  @consume.objects.select do |o|
    next if o.publisher_name.blank?
    publisher.blank? or o.publisher == publisher
  end
end
consumers() click to toggle source
# File lib/lacerda/service.rb, line 23
def consumers
  infrastructure.services.values.select do |service|
    service.consuming_from.include?(self)
  end
end
consumes?(object_name) click to toggle source
# File lib/lacerda/service.rb, line 40
def consumes?(object_name)
  @consume.object?(object_name.to_s)
end
consumes_from?(service_name, object_name) click to toggle source
# File lib/lacerda/service.rb, line 44
def consumes_from?(service_name, object_name)
  @consume.object?([service_name, object_name].join(Lacerda::SCOPE_SEPARATOR))
end
consuming_from() click to toggle source
# File lib/lacerda/service.rb, line 19
def consuming_from
  consumed_objects.map(&:publisher).uniq
end
published_objects() click to toggle source
# File lib/lacerda/service.rb, line 48
def published_objects
  @publish.objects
end
publishes?(object_name) click to toggle source
# File lib/lacerda/service.rb, line 36
def publishes?(object_name)
  @publish.object?(object_name.to_s)
end
satisfies?(service, reporter = nil) click to toggle source
# File lib/lacerda/service.rb, line 52
def satisfies?(service, reporter = nil)
  Lacerda.validate_reporter(reporter)
  @publish.satisfies?(service, reporter)
end
satisfies_consumers?(options = {}) click to toggle source
# File lib/lacerda/service.rb, line 57
def satisfies_consumers?(options = {})
  reporter = Lacerda.validate_reporter(options.fetch(:reporter, nil))

  @errors = {}
  consumers.each do |consumer|
    @publish.satisfies?(consumer, reporter)
    next if @publish.errors.empty?
    @errors["#{name} -> #{consumer.name}"] = @publish.errors
  end
  @errors.empty?
end
validate_internal_publish_object!(type, data) click to toggle source
# File lib/lacerda/service.rb, line 81
def validate_internal_publish_object!(type, data)
  object_description = @publish.object(type, scoped: false)
  object_description.validate_data!(data)
end
validate_object_to_consume(type, data) click to toggle source
# File lib/lacerda/service.rb, line 86
def validate_object_to_consume(type, data)
  validate_object_to_consume!(type, data)
  true
rescue
  false
end
validate_object_to_consume!(type, data) click to toggle source
# File lib/lacerda/service.rb, line 93
def validate_object_to_consume!(type, data)
  object_description = @consume.object(type)
  object_description.validate_data!(data)
end
validate_object_to_publish(type, data) click to toggle source
# File lib/lacerda/service.rb, line 69
def validate_object_to_publish(type, data)
  validate_object_to_publish!(type, data)
  true
rescue
  false
end
validate_object_to_publish!(type, data) click to toggle source
# File lib/lacerda/service.rb, line 76
def validate_object_to_publish!(type, data)
  object_description = @publish.object(type)
  object_description.validate_data!(data)
end

Private Instance Methods

load_contracts() click to toggle source
# File lib/lacerda/service.rb, line 109
def load_contracts
  @publish = Lacerda::PublishSpecification.new(self, File.join(@data_dir, "publish.schema.json"))
  @consume = Lacerda::ConsumeSpecification.new(self, File.join(@data_dir, "consume.schema.json"))
end