lib/data_model.rb in data_model-0.4.0 vs lib/data_model.rb in data_model-0.5.0
- old
+ new
@@ -1,35 +1,23 @@
-# typed: strict
-
require "logger"
require "bigdecimal"
require "date"
require "time"
require "bundler/setup"
require "zeitwerk"
-require "sorbet-runtime"
-loader = T.let(Zeitwerk::Loader.for_gem, Zeitwerk::Loader)
+loader = Zeitwerk::Loader.for_gem
loader.setup
module DataModel
- extend T::Sig
extend self
- TSchema = T.type_alias { T::Array[Object] }
- TData = T.type_alias { Object }
-
- # an error is a tuple of [error_type, error_context], where context
- # provides additional information about the error
- TError = T.type_alias { [Symbol, Object] }
-
- # a map of symbol => type, suitable for sending to a TypeRegistry
- TTypeMap = T.type_alias { T::Hash[Symbol, T.class_of(Type)] }
-
# Scan a schema and create a data model, which is a configured type.
- sig { params(schema: TSchema, registry: Registry).returns(Model) }
+ # @param schema [Array] the schema to define
+ # @param registry [Registry] the registry to use
+ # @return [Model] the model built from the schema
def define(schema, registry: Registry.instance)
scanned = Scanner.scan(schema, registry)
type = registry.type(
scanned.type,
@@ -40,10 +28,13 @@
model = Model.new(schema, type)
return model
end
- sig { params(name: Symbol, type: T.class_of(Type)).void }
+ # Register a global type, which is available to all models.
+ # @param name [Symbol] the name of the Type
+ # @param type [Type] the type to register
+ # @return [void]
def register_global_type(name, type)
Registry.register(name, type)
end
end