Sha256: 2aff6ff006a533e009fdbce2a5eeb56850fe52167738d516e1a210e59661df69
Contents?: true
Size: 731 Bytes
Versions: 4
Compression:
Stored size: 731 Bytes
Contents
# typed: strict module DataModel class Model extend T::Sig sig { params(schema: TSchema, type: Type).void } def initialize(schema, type) @schema = schema @type = type end sig { returns(TSchema) } attr_reader :schema # Validate data against the model. This will return true if the data is valid, # or false if it is not. If it is not valid, it will raise an exception. sig { params(data: TData).returns(Error) } def validate(data) _, err = @type.read(data) return err end # Read data with the model. This will return a tuple of [data, error] sig { params(data: TData).returns([TData, Error]) } def coerce(data) result = @type.read(data, coerce: true) return result end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
data_model-0.4.0 | lib/data_model/model.rb |
data_model-0.3.0 | lib/data_model/model.rb |
data_model-0.2.0 | lib/data_model/model.rb |
data_model-0.1.0 | lib/data_model/model.rb |