Sha256: 6aa4d3f91c77d99dbf947ec09f3c8cf34c694bdc0008d8dfa152a6f8643a25aa
Contents?: true
Size: 989 Bytes
Versions: 2
Compression:
Stored size: 989 Bytes
Contents
# frozen_string_literal: true class Journaled::JsonSchemaModel::Validator def initialize(schema_name) @schema_name = schema_name end def validate!(json_to_validate) JSON::Validator.validate!(json_schema, json_to_validate) end private attr_reader :schema_name def json_schema @json_schema ||= JSON.parse(json_schema_file) end def json_schema_file @json_schema_file ||= File.read(json_schema_path) end def json_schema_path @json_schema_path ||= gem_paths.detect { |path| File.exist?(path) } || raise(<<~ERROR) journaled_schemas/#{schema_name}.json not found in any of #{Journaled.schema_providers.map { |sp| "#{sp}.root" }.join(', ')} You can add schema providers as follows: # config/initializers/journaled.rb Journaled.schema_providers << MyGem::Engine ERROR end def gem_paths Journaled.schema_providers.map do |engine| engine.root.join "journaled_schemas/#{schema_name}.json" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
journaled-6.0.0 | app/models/journaled/json_schema_model/validator.rb |
journaled-5.3.2 | app/models/journaled/json_schema_model/validator.rb |