aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb
blob: dd97393eac7bbc5b744f05ec30da11381a400ae9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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

          def type
            :uuid
          end

          def type_cast(value)
            value.to_s[RFC_4122, 0]
          end
        end
      end
    end
  end
end