Sha256: 5c6ffc5ea7751491d08267efb02688ca9aafdbf2304c114b4912a512b28b0d43

Contents?: true

Size: 1.47 KB

Versions: 10

Compression:

Stored size: 1.47 KB

Contents

require 'json-schema'

module Hyrax
  module Arkivo
    ITEM_SCHEMA = {
      type: 'object',
      properties: {
        token: { type: 'string', required: true },
        metadata: {
          type: 'object',
          required: true,
          properties: {
            title: { type: 'string', required: true },
            rights: { type: 'string', required: true },
            resourceType: { type: 'string' },
            description: { type: 'string' },
            publisher: { type: 'string' },
            dateCreated: { type: 'string' },
            basedNear: { type: 'string' },
            identifier: { type: 'string' },
            url: { type: 'string' },
            language: { type: 'string' }
          }
        },
        file: {
          type: 'object',
          required: true,
          properties: {
            base64: { type: 'string', required: true },
            md5: { type: 'string', required: true },
            filename: { type: 'string', required: true },
            contentType: { type: 'string', required: true }
          }
        }
      }
    }.freeze

    class InvalidItem < RuntimeError
    end

    class SchemaValidator
      attr_reader :item

      def initialize(item)
        @item = item
      end

      def call
        JSON::Validator.validate!(Hyrax::Arkivo::ITEM_SCHEMA, item, version: :draft3)
      rescue JSON::Schema::ValidationError => exception
        raise Hyrax::Arkivo::InvalidItem, exception.message
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
hyrax-1.1.1 lib/hyrax/arkivo/schema_validator.rb
hyrax-1.1.0 lib/hyrax/arkivo/schema_validator.rb
hyrax-1.0.5 lib/hyrax/arkivo/schema_validator.rb
hyrax-1.0.4 lib/hyrax/arkivo/schema_validator.rb
hyrax-1.0.3 lib/hyrax/arkivo/schema_validator.rb
hyrax-1.0.2 lib/hyrax/arkivo/schema_validator.rb
hyrax-1.0.1 lib/hyrax/arkivo/schema_validator.rb
hyrax-1.0.0.rc2 lib/hyrax/arkivo/schema_validator.rb
hyrax-1.0.0.rc1 lib/hyrax/arkivo/schema_validator.rb
test_hyrax-0.0.1.alpha lib/hyrax/arkivo/schema_validator.rb