aboutsummaryrefslogblamecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/type/hash_lookup_type_map.rb
blob: bb1abc77ff3c0928b63a3f253ec5c9574856b9aa (plain) (tree)
1
2
3
4
5
6
7
8
9
10



                                                 

                                     

                                                                        

           

                                                       

           
                                        
                                                                      




           
module ActiveRecord
  module ConnectionAdapters
    module Type
      class HashLookupTypeMap < TypeMap # :nodoc:
        delegate :key?, to: :@mapping

        def lookup(type, *args)
          @mapping.fetch(type, proc { default_value }).call(type, *args)
        end

        def fetch(type, *args, &block)
          @mapping.fetch(type, block).call(type, *args)
        end

        def alias_type(type, alias_type)
          register_type(type) { |_, *args| lookup(alias_type, *args) }
        end
      end
    end
  end
end