diff options
Diffstat (limited to 'activemodel/lib/active_model/type/hash_lookup_type_map.rb')
-rw-r--r-- | activemodel/lib/active_model/type/hash_lookup_type_map.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/type/hash_lookup_type_map.rb b/activemodel/lib/active_model/type/hash_lookup_type_map.rb new file mode 100644 index 0000000000..45d3515aad --- /dev/null +++ b/activemodel/lib/active_model/type/hash_lookup_type_map.rb @@ -0,0 +1,23 @@ +module ActiveModel + module Type + class HashLookupTypeMap < TypeMap # :nodoc: + def alias_type(type, alias_type) + register_type(type) { |_, *args| lookup(alias_type, *args) } + end + + def key?(key) + @mapping.key?(key) + end + + def keys + @mapping.keys + end + + private + + def perform_fetch(type, *args, &block) + @mapping.fetch(type, block).call(type, *args) + end + end + end +end |