Module: Surrealist::SchemaDefiner

Defined in:
lib/surrealist/schema_definer.rb

Overview

A class that defines a method on the object that stores the schema.

Constant Summary collapse

SCHEMA_TYPE_ERROR =
'Schema should be defined as a hash'

Class Method Summary collapse

Class Method Details

.call(klass, hash) ⇒ Hash

Defines an instance variable on the object that stores the schema.

Parameters:

  • klass (Object)

    class of the object that needs to be surrealized.

  • hash (Hash)

    the schema defined in the object’s class.

Returns:

  • (Hash)

    @__surrealist_schema variable that stores the schema of the object.

Raises:

  • Surrealist::InvalidSchemaError if schema was defined not through a hash.



18
19
20
21
22
# File 'lib/surrealist/schema_definer.rb', line 18

def call(klass, hash)
  raise Surrealist::InvalidSchemaError, SCHEMA_TYPE_ERROR unless hash.is_a?(Hash)

  Surrealist::VarsHelper.set_schema(klass, hash)
end