diff options
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb new file mode 100644 index 0000000000..033e0324bb --- /dev/null +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb @@ -0,0 +1,28 @@ +module ActiveRecord + module ConnectionAdapters + module PostgreSQL + module OID # :nodoc: + class Uuid < Type::Value # :nodoc: + RFC_4122 = %r{\A\{?[a-fA-F0-9]{4}-? + [a-fA-F0-9]{4}-? + [a-fA-F0-9]{4}-? + [1-5][a-fA-F0-9]{3}-? + [8-Bab][a-fA-F0-9]{3}-? + [a-fA-F0-9]{4}-? + [a-fA-F0-9]{4}-? + [a-fA-F0-9]{4}-?\}?\z}x + + alias_method :type_cast_for_database, :type_cast_from_database + + def type + :uuid + end + + def type_cast(value) + value.to_s[RFC_4122, 0] + end + end + end + end + end +end |