module JSONSchemer
Based on code from @robacarp found in issue 48: github.com/davishmcclurg/json_schemer/issues/48
Constants
- DEFAULT_META_SCHEMA
- DRAFT_CLASS_BY_META_SCHEMA
- FILE_URI_REF_RESOLVER
- VERSION
- WINDOWS_URI_PATH_REGEX
Public Class Methods
schema(schema, **options)
click to toggle source
# File lib/json_schemer.rb, line 51 def schema(schema, **options) case schema when String schema = JSON.parse(schema) when Pathname uri = URI.parse(File.join('file:', schema.realpath)) if options.key?(:ref_resolver) schema = FILE_URI_REF_RESOLVER.call(uri) else ref_resolver = CachedRefResolver.new(&FILE_URI_REF_RESOLVER) schema = ref_resolver.call(uri) options[:ref_resolver] = ref_resolver end schema[draft_class(schema)::ID_KEYWORD] ||= uri.to_s end draft_class(schema).new(schema, **options) end
Private Class Methods
draft_class(schema)
click to toggle source
# File lib/json_schemer.rb, line 71 def draft_class(schema) meta_schema = schema.is_a?(Hash) && schema.key?('$schema') ? schema['$schema'] : DEFAULT_META_SCHEMA DRAFT_CLASS_BY_META_SCHEMA[meta_schema] || raise(UnsupportedMetaSchema, meta_schema) end