Module: DataModel

Extended by:
DataModel
Included in:
DataModel
Defined in:
lib/data_model.rb,
lib/data_model/type.rb,
lib/data_model/error.rb,
lib/data_model/model.rb,
lib/data_model/errors.rb,
lib/data_model/struct.rb,
lib/data_model/boolean.rb,
lib/data_model/builtin.rb,
lib/data_model/logging.rb,
lib/data_model/scanner.rb,
lib/data_model/testing.rb,
lib/data_model/version.rb,
lib/data_model/registry.rb,
lib/data_model/builtin/or.rb,
lib/data_model/fixtures/or.rb,
lib/data_model/builtin/date.rb,
lib/data_model/builtin/hash.rb,
lib/data_model/builtin/time.rb,
lib/data_model/builtin/array.rb,
lib/data_model/builtin/float.rb,
lib/data_model/fixtures/date.rb,
lib/data_model/fixtures/hash.rb,
lib/data_model/fixtures/time.rb,
lib/data_model/builtin/object.rb,
lib/data_model/builtin/string.rb,
lib/data_model/builtin/symbol.rb,
lib/data_model/fixtures/array.rb,
lib/data_model/fixtures/float.rb,
lib/data_model/builtin/boolean.rb,
lib/data_model/builtin/integer.rb,
lib/data_model/builtin/numeric.rb,
lib/data_model/fixtures/object.rb,
lib/data_model/fixtures/string.rb,
lib/data_model/fixtures/symbol.rb,
lib/data_model/fixtures/boolean.rb,
lib/data_model/fixtures/example.rb,
lib/data_model/fixtures/integer.rb,
lib/data_model/fixtures/numeric.rb,
lib/data_model/testing/minitest.rb,
lib/data_model/builtin/big_decimal.rb,
lib/data_model/fixtures/big_decimal.rb

Defined Under Namespace

Modules: Builtin, Errors, Logging, Scanner, Testing Classes: Boolean, Error, Model, Registry, Struct, Type

Constant Summary collapse

VERSION =
"0.6.1"

Instance Method Summary collapse

Instance Method Details

#define(schema, registry: Registry.instance) ⇒ Model

Scan a schema and create a data model, which is a configured type.

Parameters:

  • schema (Array)

    the schema to define

  • registry (Registry) (defaults to: Registry.instance)

    the registry to use

Returns:

  • (Model)

    the model built from the schema



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/data_model.rb', line 19

def define(schema, registry: Registry.instance)
	scanned = Scanner.scan(schema, registry)

	type = registry.type(
		scanned.type,
		args: scanned.args,
		params: scanned.params,
	)

	model = Model.new(schema, type)

	return model
end

#register_global_type(name, type) ⇒ void

This method returns an undefined value.

Register a global type, which is available to all models.

Parameters:

  • name (Symbol)

    the name of the Type

  • type (Type)

    the type to register



37
38
39
# File 'lib/data_model.rb', line 37

def register_global_type(name, type)
	Registry.register(name, type)
end