Sha256: 167ef01f13d533345ef2565c4816d02baeb6b6871b15380bd0e496a8d4279fe1
Contents?: true
Size: 1.11 KB
Versions: 3
Compression:
Stored size: 1.11 KB
Contents
require "json_schema_rails/version" require "json_schema_rails/errors" require "json_schema_rails/loaders" require "json_schema_rails/schema_validator" require "json_schema_rails/engine" if defined?(Rails) require "json_schema_rails/json_schema/schema" require "json_schema_rails/json_schema/parser" module JsonSchemaRails def self.schema_loader @schema_loader ||= Loaders::Directory.new('app/schemas') end def self.schema_loader=(loader) @schema_loader = loader end def self.validate(schema_name, data) schema = lookup_schema!(schema_name) schema.validate(data) end def self.validate!(schema_name, data) schema = lookup_schema!(schema_name) valid, errors = schema.validate(data) unless valid raise ValidationError.from_errors(errors, schema, schema_name) end true end def self.lookup_schema(schema_name) lookup_schema!(schema_name) rescue SchemaNotFound nil end def self.lookup_schema!(schema_name) Array(schema_name).each do |name| schema = schema_loader.load_schema(name) return schema if schema end raise SchemaNotFound end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
json_schema_rails-0.2.1 | lib/json_schema_rails.rb |
json_schema_rails-0.2.0 | lib/json_schema_rails.rb |
json_schema_rails-0.1.0 | lib/json_schema_rails.rb |