9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/activerecord-native_db_types_override/options.rb', line 9
def configure(hash)
puts "ActiveRecord - Native Database Types Override #{NativeDbTypesOverride::VERSION}" if NativeDbTypesOverride.debug?
hash.keys.each do |key|
begin
clazz = convert_symbol_to_class(key)
rescue => e
puts "Unable to get adapter class for #{key.inspect}. Try specifying the adapter class itself as the key in the hash in NativeDbTypesOverride.configure(). Error: #{e.message}\n#{e.backtrace.join("\n")}"
end
new_types = {}
begin
new_types = clazz.const_get('NATIVE_DATABASE_TYPES')
rescue
puts "No NATIVE_DATABASE_TYPES constant on #{clazz} so expecting the whole types hash to be specified via NativeDbTypesOverride.configure()" if NativeDbTypesOverride.debug?
end
new_types = new_types.merge(hash[key])
puts "Defining #{clazz}.native_database_types as #{new_types.inspect}" if NativeDbTypesOverride.debug?
clazz.class_eval "def native_database_types; #{new_types.inspect}; end"
end
end
|