Sha256: 295fff85e9badf97a58bc2b36fd0e053b3077ab9f7ed85a6e294a0165ff1d412

Contents?: true

Size: 1.27 KB

Versions: 14

Compression:

Stored size: 1.27 KB

Contents

require 'fun_with_json_api/exception'

module FunWithJsonApi
  class SchemaValidator
    def self.check(document, deserializer, resource)
      new(document, deserializer, resource).check
    end

    private_class_method :new

    attr_reader :document
    attr_reader :deserializer
    attr_reader :resource

    def initialize(document, deserializer, resource)
      @document = FunWithJsonApi.sanitize_document(document)
      @deserializer = deserializer
      @resource = resource
    end

    def check
      FunWithJsonApi::SchemaValidators::CheckDocumentTypeMatchesResource.call(self)
      FunWithJsonApi::SchemaValidators::CheckDocumentIdMatchesResource.call(self)
      FunWithJsonApi::SchemaValidators::CheckAttributes.call(document, deserializer)
      FunWithJsonApi::SchemaValidators::CheckRelationships.call(document, deserializer)
    end

    def document_id
      @document_id ||= document['data']['id']
    end

    def document_type
      @document_type ||= document['data']['type']
    end

    def resource_id
      @resource_id ||= resource.send(deserializer.id_param).to_s
    end

    def resource_type
      @resource_type ||= deserializer.type
    end
  end
end

# Load known Schema Validators
Dir["#{File.dirname(__FILE__)}/schema_validators/**/*.rb"].each { |f| require f }

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
fun_with_json_api-0.0.10.2 lib/fun_with_json_api/schema_validator.rb
fun_with_json_api-0.0.10.1 lib/fun_with_json_api/schema_validator.rb
fun_with_json_api-0.0.10 lib/fun_with_json_api/schema_validator.rb
fun_with_json_api-0.0.9 lib/fun_with_json_api/schema_validator.rb
fun_with_json_api-0.0.8.2 lib/fun_with_json_api/schema_validator.rb
fun_with_json_api-0.0.8.1 lib/fun_with_json_api/schema_validator.rb
fun_with_json_api-0.0.8 lib/fun_with_json_api/schema_validator.rb
fun_with_json_api-0.0.7 lib/fun_with_json_api/schema_validator.rb
fun_with_json_api-0.0.6.pre.alpha.2 lib/fun_with_json_api/schema_validator.rb
fun_with_json_api-0.0.6.pre.alpha.1 lib/fun_with_json_api/schema_validator.rb
fun_with_json_api-0.0.6.1 lib/fun_with_json_api/schema_validator.rb
fun_with_json_api-0.0.6 lib/fun_with_json_api/schema_validator.rb
fun_with_json_api-0.0.5 lib/fun_with_json_api/schema_validator.rb
fun_with_json_api-0.0.4 lib/fun_with_json_api/schema_validator.rb