Sha256: 4ec97b829d0a42aaab9fee9b67212729ef835f0ecb0941cf4dbf6b58ee03a3c9
Contents?: true
Size: 995 Bytes
Versions: 3
Compression:
Stored size: 995 Bytes
Contents
module DataModel # A model is a schema and a type. It is the primary interface for interacting # with the data_model gem. class Model # Create a new model. # @param schema [Array] the schema to define # @param type [Type] the type to use # @return [void] def initialize(schema, type) @schema = schema @type = type end # @return [Array] the schema configured 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. # @param data [Hash] the data to validate # @return [Boolean] true if the data is valid, false if it is not def validate(data) _, err = @type.read(data) return err end # Read data with the model. This will return a tuple of [data, error] # @param data [Hash] the data to read # @return [Array] a tuple of [data, error] def coerce(data) result = @type.read(data, coerce: true) return result end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
data_model-0.6.1 | lib/data_model/model.rb |
data_model-0.6.0 | lib/data_model/model.rb |
data_model-0.5.0 | lib/data_model/model.rb |