aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type_caster/map.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/type_caster/map.rb')
-rw-r--r--activerecord/lib/active_record/type_caster/map.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/type_caster/map.rb b/activerecord/lib/active_record/type_caster/map.rb
new file mode 100644
index 0000000000..663cdadb03
--- /dev/null
+++ b/activerecord/lib/active_record/type_caster/map.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+module ActiveRecord
+ module TypeCaster
+ class Map # :nodoc:
+ def initialize(types)
+ @types = types
+ end
+
+ def type_cast_for_database(attr_name, value)
+ return value if value.is_a?(Arel::Nodes::BindParam)
+ type = types.type_for_attribute(attr_name)
+ type.serialize(value)
+ end
+
+ private
+ attr_reader :types
+ end
+ end
+end