class Lacerda::ConsumeSpecification

Public Class Methods

new(service, schema_or_file) click to toggle source

We will remove any properties from the schema that are not referencing a published object from another service, but that are just local definitions i.e.

{
  "type": "object",
  "definitions": {
    "message_properties": { ...},
    "service::message": {...}
    "
  }
  "properties": {
    "message_properties": { "$ref": "#/message_properties }, <- remove
    "service::message": { "$ref": "#/service::message" } <- keep
  }
}
Calls superclass method Lacerda::Specification::new
# File lib/lacerda/consume_specification.rb, line 24
def initialize(service, schema_or_file)
  super
  return unless @schema['properties']
  @schema['properties'] = @schema['properties'].keep_if do |k, v|
    !!k.index(Lacerda::SCOPE_SEPARATOR)
  end
end

Public Instance Methods

object(name) click to toggle source
# File lib/lacerda/consume_specification.rb, line 51
def object(name)
  underscored_name = Lacerda.underscore(name)
  schema_dup = Lacerda.deep_copy(@schema)

  # It's critical to delete this object from the definitions
  # or else the json validator gem will go into an endless loop
  object_schema = schema_dup['definitions'].delete underscored_name.to_s

  msg = "Unknown object type: #{underscored_name.to_s.to_json} not in #{schema['definitions'].keys.to_json} - did you specify it in consume.mson?"
  raise Lacerda::Service::InvalidObjectTypeError.new(msg) unless object_schema

  # Copy the definitions of our schema into the schema for the
  # object in case its properties include json pointers
  object_schema['definitions'] = schema_dup['definitions']

  Lacerda::ConsumedObject.new(service, name, object_schema)
end
object?(name) click to toggle source
# File lib/lacerda/consume_specification.rb, line 46
def object?(name)
  underscored_name = Lacerda.underscore(name)
  !!@schema[:definitions][underscored_name]
end
object_description_class() click to toggle source
# File lib/lacerda/consume_specification.rb, line 32
def object_description_class
  Lacerda::ConsumedObject
end
scoped_schema(service) click to toggle source
# File lib/lacerda/consume_specification.rb, line 36
def scoped_schema(service)
  service_name_prefix = Lacerda.underscore(service.name + Lacerda::SCOPE_SEPARATOR)

  filtered_schema = Lacerda.deep_copy(schema)
  filtered_schema['properties'].select! do |k|
    Lacerda.underscore(k).start_with?(service_name_prefix)
  end
  filtered_schema
end