module Motor::ActiveRecordUtils::Types

Constants

DEFAULT_TYPE
MUTEX
UNIFIED_TYPES

Public Instance Methods

all() click to toggle source
# File lib/motor/active_record_utils/types.rb, line 29
def all
  @all || MUTEX.synchronize do
    @all ||= build_types_hash
  end
end
build_types_hash() click to toggle source
# File lib/motor/active_record_utils/types.rb, line 48
def build_types_hash
  type_map = ActiveRecord::Base.connection.send(:type_map)

  type_map.instance_variable_get('@mapping').map do |name, type|
    next unless name.is_a?(String)

    [type.call.class.to_s, name]
  end.compact.to_h
end
find_class_for_name(name) click to toggle source
# File lib/motor/active_record_utils/types.rb, line 35
def find_class_for_name(name)
  all.invert[name.to_s]
end
find_name_for_type(type) click to toggle source
# File lib/motor/active_record_utils/types.rb, line 39
def find_name_for_type(type)
  name   = all[type.subtype.class.to_s] if type.respond_to?(:subtype)
  name ||= all[type.class.to_s]

  return UNIFIED_TYPES.fetch(name, name) if name

  DEFAULT_TYPE
end