aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type/binary.rb
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2014-06-04 02:54:40 +0930
committerMatthew Draper <matthew@trebex.net>2014-06-04 02:54:40 +0930
commit7a25444f182f76696ab1f0824464025a9e121f8e (patch)
treeb3dedecdebc71d108a34fcf3e06eda8a07503084 /activerecord/lib/active_record/type/binary.rb
parent4bcf9029452e0c760af04faab6b549710401e8cf (diff)
parent74a756a8b43e2eb5e743d32fa4f6089be2246a58 (diff)
downloadrails-7a25444f182f76696ab1f0824464025a9e121f8e.tar.gz
rails-7a25444f182f76696ab1f0824464025a9e121f8e.tar.bz2
rails-7a25444f182f76696ab1f0824464025a9e121f8e.zip
Merge pull request #15486 from sgrif/sg-binary-quoting
Refactor quoting of binary data to not be based on the column type
Diffstat (limited to 'activerecord/lib/active_record/type/binary.rb')
-rw-r--r--activerecord/lib/active_record/type/binary.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/type/binary.rb b/activerecord/lib/active_record/type/binary.rb
index e34b7bb268..9d10c91fc1 100644
--- a/activerecord/lib/active_record/type/binary.rb
+++ b/activerecord/lib/active_record/type/binary.rb
@@ -12,6 +12,24 @@ module ActiveRecord
def klass
::String
end
+
+ def type_cast_for_database(value)
+ Data.new(super)
+ end
+
+ class Data
+ def initialize(value)
+ @value = value
+ end
+
+ def to_s
+ @value
+ end
+
+ def hex
+ @value.unpack('H*')[0]
+ end
+ end
end
end
end