module SchemaTest

Constants

CLOSING_COMMENT
OPENING_COMMENT
SCHEMA_VERSION
VERSION

Public Class Methods

collection(name, of:, **attributes) click to toggle source

Explicitly define a new schema collection (an array of other schema objects)

# File lib/schema_test.rb, line 45
def collection(name, of:, **attributes)
  SchemaTest::Collection.new(name, of, attributes)
end
configuration() click to toggle source
# File lib/schema_test.rb, line 25
def configuration
  @configuration ||= SchemaTest::Configuration.new
end
configure() { |configuration| ... } click to toggle source

Yields a configuration object, which can be used to set up various aspects of the library

# File lib/schema_test.rb, line 21
def configure
  yield configuration
end
define(name, collection: nil, **attributes, &block) click to toggle source

Define a new schema

# File lib/schema_test.rb, line 35
def define(name, collection: nil, **attributes, &block)
  definition = SchemaTest::Definition.new(name, attributes, &block)
  if collection
    collection(collection, of: name, version: attributes[:version])
  end
  definition
end
load!() click to toggle source

Recursively loads all files under the `definition_paths` directories

# File lib/schema_test.rb, line 30
def load!
  load_definitions
end
reset!() click to toggle source
# File lib/schema_test.rb, line 14
def reset!
  @configuration = nil
  SchemaTest::Definition.reset!
end
validate_json(json, definition_or_schema) click to toggle source

Validate some JSON data against a schema or schema definition

# File lib/schema_test.rb, line 50
def validate_json(json, definition_or_schema)
  validator = SchemaTest::Validator.new(json)
  if definition_or_schema.is_a?(SchemaTest::Property::Object)
    validator.validate_using_definition(definition_or_schema)
  else
    validator.validate_using_json_schema(definition_or_schema)
  end
end

Private Class Methods

load_definitions() click to toggle source
# File lib/schema_test.rb, line 61
def load_definitions
  globbed_paths = configuration.definition_paths.map { |path| path.join('**', '*.rb') }
  Dir[globbed_paths.join(',')].each do |schema_file|
    require schema_file
  end
end