aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-06-02 08:58:12 +0200
committerYves Senn <yves.senn@gmail.com>2014-06-02 08:58:12 +0200
commitf17fa8ef6f2abffeea5398cc450172c0975cad27 (patch)
treed6ec8cd97ef8dddf52472a5251d1fc90cfe0ac13 /activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb
parent4c66ab2b2181a2c1d7163c24ce8aec0dbb3bef7b (diff)
downloadrails-f17fa8ef6f2abffeea5398cc450172c0975cad27.tar.gz
rails-f17fa8ef6f2abffeea5398cc450172c0975cad27.tar.bz2
rails-f17fa8ef6f2abffeea5398cc450172c0975cad27.zip
pg, inline casting methods into `OID::Type` objects.
This inlines casting for the most obvious types. The rest will follow eventually. I need to put some tests in place, to make sure that the inlining is not causing regressions. /cc @sgrif
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb
index 9b2d887d07..dc077993c5 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb
@@ -5,7 +5,12 @@ module ActiveRecord
class Bit < Type::String
def type_cast(value)
if ::String === value
- ConnectionAdapters::PostgreSQLColumn.string_to_bit value
+ case value
+ when /^0x/i
+ value[2..-1].hex.to_s(2) # Hexadecimal notation
+ else
+ value # Bit-string notation
+ end
else
value
end