Class: DataMapper::Type
Direct Known Subclasses
DataMapper::Types::Boolean, DataMapper::Types::Decimal, DataMapper::Types::Discriminator, DataMapper::Types::Object, DataMapper::Types::Serial, DataMapper::Types::Text
Constant Summary collapse
- PROPERTY_OPTIONS =
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
[ :accessor, :reader, :writer, :lazy, :default, :key, :serial, :field, :size, :length, :format, :index, :unique_index, :auto_validation, :validates, :unique, :precision, :scale, :min, :max, :allow_nil, :allow_blank, :required ]
Class Method Summary collapse
-
.bind(property) ⇒ Object
A hook to allow types to extend or modify property it’s bound to.
- .configure(primitive_type, options) ⇒ Object private
-
.dump(value, property) ⇒ Object
Stub instance method for dumping.
- .inherited(base) ⇒ Object
-
.load(value, property) ⇒ Object
Stub instance method for loading.
- .nullable(value) ⇒ Object
-
.options ⇒ Hash
Gives all the options set on this type.
-
.primitive(primitive = nil) ⇒ Class
Ruby primitive type to use as basis for this type.
Class Method Details
.bind(property) ⇒ Object
A hook to allow types to extend or modify property it’s bound to. Implementations are not supposed to modify the state of the type class, and should produce no side-effects on the type class.
204 205 206 |
# File 'lib/dm-core/type.rb', line 204 def self.bind(property) # no op end |
.configure(primitive_type, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/dm-core/type.rb', line 104 def configure(primitive_type, ) warn "DataMapper.Type.configure is deprecated, specify the primitive and options explicitly (#{caller[0]})" @_primitive_type = primitive_type @_options = def self.inherited(base) base.primitive @_primitive_type @_options.each { |key, value| base.send(key, value) } end self end |
.dump(value, property) ⇒ Object
Stub instance method for dumping
185 186 187 |
# File 'lib/dm-core/type.rb', line 185 def self.dump(value, property) value end |
.inherited(base) ⇒ Object
110 111 112 113 |
# File 'lib/dm-core/type.rb', line 110 def self.inherited(base) base.primitive @_primitive_type @_options.each { |key, value| base.send(key, value) } end |
.load(value, property) ⇒ Object
Stub instance method for loading
197 198 199 |
# File 'lib/dm-core/type.rb', line 197 def self.load(value, property) value end |
.nullable(value) ⇒ Object
156 157 158 159 160 |
# File 'lib/dm-core/type.rb', line 156 def nullable(value) # :required is preferable to :allow_nil, but :nullable maps precisely to :allow_nil warn "#nullable is deprecated, use #required instead (#{caller[0]})" allow_nil(value) end |
.options ⇒ Hash
Gives all the options set on this type
167 168 169 170 171 172 173 174 |
# File 'lib/dm-core/type.rb', line 167 def = {} PROPERTY_OPTIONS.each do |method| next if (value = send(method)).nil? [method] = value end end |
.primitive(primitive = nil) ⇒ Class
Ruby primitive type to use as basis for this type. See Property::PRIMITIVES for list of types.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/dm-core/type.rb', line 128 def primitive(primitive = nil) return @primitive if primitive.nil? @primitive = primitive return unless @primitive.respond_to?(:options) = @primitive. return unless .respond_to?(:each) # inherit the options from the primitive if any .each do |key, value| send(key, value) unless send(key) end end |