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) ⇒ 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) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lacerda/publish_specification.rb', line 28 def object(name) scoped_name = scopify_name(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 scoped_name.to_s unless object_schema msg = "Unknown object type: #{scoped_name.to_s.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, scoped_name, object_schema) end |
#object?(name) ⇒ Boolean
23 24 25 26 |
# File 'lib/lacerda/publish_specification.rb', line 23 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 |
# 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_satisfied, consumer, result) result end |