Hi All,

I'm auto building some HTML forms from DM models, so I need a
consistent way to map a property type to an html element. I thought I
would just use the class name, but playing around I tried the
following:

require 'rubygems'
require 'dm-core'
require 'dm-types'

class T
  include DataMapper::Resource
  property :serial, Serial
  property :string, String
  property :slug,   Slug
  property :text,   Text
  property :dt,     DateTime
  property :bool,   Boolean
  property :float,  Float
  property :bcrypt, BCryptHash
  property :enum,   Enum[:a, :b, :c]
  property :flag,   Flag[:a, :b, :c]
end

T.properties.each do |p|
  puts p.class
end

Which yields:

DataMapper::Property::String
DataMapper::Property::Slug
DataMapper::Property::Text
DataMapper::Property::DateTime
DataMapper::Property::Boolean
DataMapper::Property::Float
DataMapper::Property::BCryptHash
#<Class:0x1015a1d68>
#<Class:0x10158b540>

The last two (Enum & Flag) obviously didn't come out as expected. If I
use T.enum.kind_of?(::DataMapper::Property::Enum) then it will show
true.

So the question, I suppose, is there a consistent way to look at all
the properties and determine their type?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to