class JsonMatchers::Matcher

Attributes

document_store[R]
errors[RW]
schema_path[R]

Public Class Methods

new(schema_path) click to toggle source
# File lib/json_matchers/matcher.rb, line 7
def initialize(schema_path)
  @schema_path = schema_path
  @document_store = build_and_populate_document_store
end

Public Instance Methods

matches?(payload) click to toggle source
# File lib/json_matchers/matcher.rb, line 12
def matches?(payload)
  self.errors = validator.validate(payload)

  errors.empty?
end
validation_failure_message() click to toggle source
# File lib/json_matchers/matcher.rb, line 18
def validation_failure_message
  errors.first.to_s
end

Private Instance Methods

build_and_populate_document_store() click to toggle source
# File lib/json_matchers/matcher.rb, line 31
def build_and_populate_document_store
  document_store = JsonSchema::DocumentStore.new

  traverse_schema_root_with_first_level_symlinks.
    map { |path| Pathname.new(path) }.
    map { |schema_path| Parser.new(schema_path).parse }.
    map { |schema| document_store.add_schema(schema) }.
    each { |schema| schema.expand_references!(store: document_store) }

  document_store
end
validator() click to toggle source
# File lib/json_matchers/matcher.rb, line 27
def validator
  Validator.new(schema_path: schema_path, document_store: document_store)
end