diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-05-22 09:12:23 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-05-22 09:14:15 -0700 |
commit | ecf4ad7cca206e2cf99ca16e57e17648e726877a (patch) | |
tree | 0a8e826707d2b8b2441972e35e6c90f35c8ac1bf /activerecord/lib/active_record/connection_adapters/type/type_map.rb | |
parent | 110d3d0c0bceddd05cab86c0463f0aa71df815cb (diff) | |
download | rails-ecf4ad7cca206e2cf99ca16e57e17648e726877a.tar.gz rails-ecf4ad7cca206e2cf99ca16e57e17648e726877a.tar.bz2 rails-ecf4ad7cca206e2cf99ca16e57e17648e726877a.zip |
Allow additional arguments to be used during type map lookups
Determining things like precision and scale in postgresql will require
the given blocks to take additional arguments besides the OID.
- Adds the ability to handle additional arguments to `TypeMap`
- Passes the column type to blocks when looking up PG types
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/type/type_map.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/type/type_map.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/type/type_map.rb b/activerecord/lib/active_record/connection_adapters/type/type_map.rb index d89171a820..48b8b51417 100644 --- a/activerecord/lib/active_record/connection_adapters/type/type_map.rb +++ b/activerecord/lib/active_record/connection_adapters/type/type_map.rb @@ -6,13 +6,13 @@ module ActiveRecord @mapping = {} end - def lookup(lookup_key) + def lookup(lookup_key, *args) matching_pair = @mapping.reverse_each.detect do |key, _| key === lookup_key end if matching_pair - matching_pair.last.call(lookup_key) + matching_pair.last.call(lookup_key, *args) else default_value end @@ -29,9 +29,9 @@ module ActiveRecord end def alias_type(key, target_key) - register_type(key) do |sql_type| + register_type(key) do |sql_type, *args| metadata = sql_type[/\(.*\)/, 0] - lookup("#{target_key}#{metadata}") + lookup("#{target_key}#{metadata}", *args) end end |