Class: Ardm::Property::UUID
- Inherits:
-
String
- Object
- Ardm::Property
- Object
- String
- Ardm::Property::UUID
- Defined in:
- lib/ardm/property/uuid.rb
Overview
UUID Type First run at this, because I need it. A few caveats:
* Only works on postgres, using the built-in native uuid type.
To make it work in mysql, you'll have to add a typemap entry to
the mysql_adapter. I think. I don't have mysql handy, so I'm
not going to try. For SQLite, this will have to inherit from the
String primitive
* Won't accept a random default, because of the namespace clash
between this and the UUIDtools gem. Also can't set the default
type to UUID() (postgres-contrib's native generator) and
automigrate, because auto_migrate! tries to make it a string "UUID()"
Feel free to enchance this, and delete these caveats when they’re fixed.
-- Rando Sept 25, 08
Actually, setting the primitive to “UUID” is not neccessary and causes a segfault when trying to query uuid’s from the database. The primitive should be a class which has been added to the do driver you are using. Also, it’s only neccessary to add a class to the do drivers to use as a primitive when a value cannot be represented as a string. A uuid can be represented as a string, so setting the primitive to String ensures that the value argument is a String containing the uuid in string form.
<strike>It is still neccessary to add the UUID entry to the type map for each different adapter with their respective database primitive.</strike>
The method that generates the SQL schema from the typemap currently ignores the size attribute from the type map if the primitive type is String. The causes the generated SQL statement to contain a size for a UUID column (e.g. id UUID(50)), which causes a syntax error in postgres. Until this is resolved, you will have to manually change the column type to UUID in a migration, if you want to use postgres’ built in UUID type.
-- benburkert Nov 15, 08
Constant Summary
Constants inherited from String
Constants inherited from Ardm::Property
INVALID_NAMES, Infinity, JSON, OPTIONS, PRIMITIVES, VISIBILITY_OPTIONS
Instance Attribute Summary
Attributes inherited from Ardm::Property
#allow_blank, #allow_nil, #coercion_method, #default, #dump_as, #index, #instance_variable_name, #load_as, #model, #name, #options, #reader_visibility, #required, #unique_index, #writer_visibility
Instance Method Summary collapse
Methods inherited from String
Methods inherited from Object
#marshal, #to_child_key, #unmarshal
Methods inherited from Ardm::Property
accept_options, accepted_options, #allow_blank?, #allow_nil?, #assert_valid_value, #bind, demodulize, demodulized_names, descendants, determine_class, #field, find_class, #get, #get!, inherited, #inspect, #key?, #lazy?, #loaded?, options, primitive, #primitive, #primitive?, #properties, #required?, #serial?, #set, #set!, #set_default_value, #unique?, #valid?, #value_dumped?, #value_loaded?
Methods included from Equalizer
Methods included from Subject
Methods included from Assertions
Instance Method Details
#dump(value) ⇒ Object
46 47 48 |
# File 'lib/ardm/property/uuid.rb', line 46 def dump(value) value.to_s unless value.nil? end |
#load(value) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/ardm/property/uuid.rb', line 50 def load(value) if value_loaded?(value) value elsif !value.nil? UUIDTools::UUID.parse(value) end end |
#typecast(value) ⇒ Object
58 59 60 61 |
# File 'lib/ardm/property/uuid.rb', line 58 def typecast(value) return if value.nil? load(value) end |