Class: Lacerda::PublishSpecification
- Inherits:
-
Specification
- Object
- Specification
- Lacerda::PublishSpecification
- Defined in:
- lib/lacerda/publish_specification.rb
Instance Attribute Summary
Attributes inherited from Specification
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(service, schema_or_file) ⇒ PublishSpecification
constructor
A new instance of PublishSpecification.
- #object(name, scoped: true) ⇒ Object
- #object?(name) ⇒ Boolean
- #satisfies?(consumer, reporter = nil) ⇒ Boolean
Methods inherited from Specification
Constructor Details
#initialize(service, schema_or_file) ⇒ PublishSpecification
Returns a new instance of PublishSpecification.
6 7 8 |
# File 'lib/lacerda/publish_specification.rb', line 6 def initialize(service, schema_or_file) super end |
Instance Method Details
#errors ⇒ Object
10 11 12 13 |
# File 'lib/lacerda/publish_specification.rb', line 10 def errors return [] unless @comparator @comparator.errors end |
#object(name, scoped: true) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lacerda/publish_specification.rb', line 29 def object(name, scoped: true) object_name = scoped ? scopify_name(name) : Lacerda.underscore(name.to_s) 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 object_name.to_s unless object_schema msg = "Unknown object type: #{object_name.to_s.to_json} not in #{schema['definitions'].keys.to_json} - did you specify it in publish.mson?" raise Lacerda::Service::InvalidObjectTypeError.new(msg) end # 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::PublishedObject.new(service, object_name, object_schema) end |
#object?(name) ⇒ Boolean
24 25 26 27 |
# File 'lib/lacerda/publish_specification.rb', line 24 def object?(name) scoped_name = scopify_name(name) !!@schema[:definitions][scoped_name] end |
#satisfies?(consumer, reporter = nil) ⇒ Boolean
15 16 17 18 19 20 21 22 |
# File 'lib/lacerda/publish_specification.rb', line 15 def satisfies?(consumer, reporter = nil) Lacerda.validate_reporter(reporter) @comparator = Compare::JsonSchema.new(@schema) result = @comparator.contains?(consumer.consume.scoped_schema(service), consumer.name) reporter.try(:consume_specification_errors,consumer, errors) reporter.try(:consume_specification_satisfied, consumer, result) result end |