Sha256: 21e157600ed945a77e5129f510035c773f488d949a1ee803017fadc6f8f9a47d

Contents?: true

Size: 1022 Bytes

Versions: 15

Compression:

Stored size: 1022 Bytes

Contents

require 'jschema'
module Validator
  class JSchema < Base

    def initialize(files_to_validate)
      @files_to_validate = files_to_validate
      schema_data = File.read("#{File.dirname(__FILE__)}/schema.json")
      schema_json = JSON.parse(schema_data)
      @meta_schema = ::JSchema.build(schema_json)
    end

    def validate(schema)
      schema_to_test = JSON.parse(schema)
      result = @meta_schema.validate schema_to_test
      if !result || result.length == 0
        success << schema_to_test['title'] || schema_to_test.keys[0]
      else
        errors << "Schema validation failed: #{schema_to_test['title']}\n#{result.join("\n")}"
      end
    end

    def use_for_validation(schema)
      schema_to_test = JSON.parse(schema)
      begin
       ::JSchema.build(schema_to_test)
      rescue
        errors << "Data validation failed: #{schema_to_test['title']}\n#{$!}"
        # puts $!.backtrace
      else
        success << schema_to_test['title'] || schema_to_test.keys[0]
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
fidor_schema-0.10.12 lib/validator/j_schema.rb
fidor_schema-0.10.11 lib/validator/j_schema.rb
fidor_schema-0.10.10 lib/validator/j_schema.rb
fidor_schema-0.10.9 lib/validator/j_schema.rb
fidor_schema-0.10.8 lib/validator/j_schema.rb
fidor_schema-0.10.7 lib/validator/j_schema.rb
fidor_schema-0.10.6 lib/validator/j_schema.rb
fidor_schema-0.10.5 lib/validator/j_schema.rb
fidor_schema-0.10.4 lib/validator/j_schema.rb
fidor_schema-0.10.2 lib/validator/j_schema.rb
fidor_schema-0.10.1 lib/validator/j_schema.rb
fidor_schema-0.10.0 lib/validator/j_schema.rb
fidor_schema-0.8.0 lib/validator/j_schema.rb
fidor_schema-0.7.0 lib/validator/j_schema.rb
fidor_schema-0.6.0 lib/validator/j_schema.rb