--- !ruby/object:RI::ClassDescription 
attributes: []

class_methods: 
- !ruby/object:RI::MethodSummary 
  name: bind
- !ruby/object:RI::MethodSummary 
  name: configure
- !ruby/object:RI::MethodSummary 
  name: dump
- !ruby/object:RI::MethodSummary 
  name: inherited
- !ruby/object:RI::MethodSummary 
  name: load
- !ruby/object:RI::MethodSummary 
  name: options
- !ruby/object:RI::MethodSummary 
  name: primitive
comment: 
- !ruby/struct:SM::Flow::H 
  level: 1
  text: Types
- !ruby/struct:SM::Flow::P 
  body: 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.
- !ruby/struct:SM::Flow::P 
  body: To see complete list of supported types, see documentation for Property::PRIMITIVES. dm-types library provides less common types such as ip address, uuid, json, yaml, uri, slug, version, file path, bcrypt hash and so forth.
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Defining new Types
- !ruby/struct:SM::Flow::P 
  body: To define a new type, subclass DataMapper::Type, pick ruby primitive, and set the options for this type.
- !ruby/struct:SM::Flow::VERB 
  body: "  class LowerCase &lt; DataMapper::Type\n    primitive        String\n    auto_validation  true\n    length           255\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: Following this, you will be able to use LowerCase as a type for any given property. If special materialization and serialization is required, override the class methods
- !ruby/struct:SM::Flow::VERB 
  body: "  class LowerCase &lt; DataMapper::Type\n    primitive        String\n    auto_validation  true\n    length           255\n\n    def self.dump(value, property)\n      return nil unless value\n      value.to_s.downcase\n    end\n\n    def self.load(value)\n      value\n    end\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: Properties of LowerCase type now will downcase it's values before it is persisted to the storage.
- !ruby/struct:SM::Flow::P 
  body: "One more real world example from dm-types library is a JSON type that stores values serialized as JSON, and often useful for embedded values:"
- !ruby/struct:SM::Flow::P 
  body: module DataMapper
- !ruby/struct:SM::Flow::VERB 
  body: "  module Types\n    class Json &lt; DataMapper::Type\n      primitive String\n      length    65535\n      lazy      true\n\n      def self.load(value, property)\n        if value.nil?\n          nil\n        elsif value.kind_of?(String)\n          ::JSON.load(value)\n        else\n          raise ArgumentError, '<tt>value</tt> of a property of JSON type must be nil or a String'\n        end\n      end\n\n      def self.dump(value, property)\n        if value.nil? || value.kind_of?(String)\n          value\n        else\n          ::JSON.dump(value)\n        end\n      end\n\n      def self.typecast(value, property)\n        if value.nil? || value.kind_of?(Array) || value.kind_of?(Hash)\n          value\n        else\n          ::JSON.load(value.to_s)\n        end\n      end\n    end # class Json\n    JSON = Json\n  end # module Types\n"
- !ruby/struct:SM::Flow::P 
  body: "end # module DataMapper"
constants: 
- !ruby/object:RI::Constant 
  comment: 
  - !ruby/struct:SM::Flow::P 
    body: "Until cooperation of Property and Type does not change, each must have a separate list of options, because plugins (ex.: dm-validations) may want to extend one or the other, and expects no side effects"
  name: PROPERTY_OPTIONS
  value: "[       :accessor, :reader, :writer,       :lazy, :default, :nullable, :key, :serial, :field, :size, :length,       :format, :index, :unique_index, :auto_validation,       :validates, :unique, :precision, :scale, :min, :max"
full_name: DataMapper::Type
includes: []

instance_methods: []

name: Type
superclass: Object
