Class | DataMapper::Type |
In: |
lib/dm-core/type.rb
|
Parent: | Object |
Provides means of writing custom types for properties. Each type is based on a ruby primitive and handles its own serialization and materialization, and therefore is responsible for providing those methods.
To see complete list of supported types, see documentation for DataMapper::Property::TYPES
To define a new type, subclass DataMapper::Type, pick ruby primitive, and set the options for this type.
class MyType < DataMapper::Type primitive String size 10 end
Following this, you will be able to use MyType as a type for any given property. If special materialization and serialization is required, override the class methods
class MyType < DataMapper::Type primitive String size 10 def self.dump(value, property) <work some magic> end def self.load(value) <work some magic> end end
PROPERTY_OPTIONS | = | [ :accessor, :reader, :writer, :lazy, :default, :nullable, :key, :serial, :field, :size, :length, :format, :index, :unique_index, :check, :ordinal, :auto_validation, :validates, :unique, :track, :precision, :scale |
PROPERTY_OPTION_ALIASES | = | { :size => [ :length ] |
The Ruby primitive type to use as basis for this type. See DataMapper::Property::TYPES for list of types.
@param primitive<Class, nil>
The class for the primitive. If nil is passed in, it returns the current primitive
@return <Class> if the <primitive> param is nil, return the current primitive.
@api public