Module: ActiveRecord::ConnectionAdapters::OracleEnhanced::ColumnDumper

Included in:
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter
Defined in:
lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb', line 5

def self.included(base) #:nodoc:
  base.class_eval do
    private
    alias_method_chain :column_spec,            :oracle_enhanced
    alias_method_chain :prepare_column_options, :oracle_enhanced
    alias_method_chain :migration_keys,         :oracle_enhanced

    def oracle_enhanced_adapter?
    # return original method if not using 'OracleEnhanced'
      if (rails_env = defined?(Rails.env) ? Rails.env : (defined?(RAILS_ENV) ? RAILS_ENV : nil)) &&
          ActiveRecord::Base.configurations[rails_env] &&
          ActiveRecord::Base.configurations[rails_env]['adapter'] != 'oracle_enhanced'
        return false
      else
        return true
      end
    end
  end
end

Instance Method Details

#column_spec_with_oracle_enhanced(column, types) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb', line 25

def column_spec_with_oracle_enhanced(column, types)
  # return original method if not using 'OracleEnhanced'
  return column_spec_without_oracle_enhanced(column, types) unless oracle_enhanced_adapter?

  spec = prepare_column_options(column, types)
  (spec.keys - [:name, :type]).each do |k|
    key_s = (k == :virtual_type ? "type: " : "#{k.to_s}: ")
    spec[k] = key_s + spec[k]
  end
  spec
end

#migration_keys_with_oracle_enhancedObject



55
56
57
58
59
60
61
# File 'lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb', line 55

def migration_keys_with_oracle_enhanced
  # TODO `& column_specs.map(&:keys).flatten` should be exetuted here
  # return original method if not using 'OracleEnhanced'
  return migration_keys_without_oracle_enhanced unless oracle_enhanced_adapter?

  [:name, :limit, :precision, :scale, :default, :null, :as, :virtual_type]
end

#prepare_column_options_with_oracle_enhanced(column, types) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb', line 37

def prepare_column_options_with_oracle_enhanced(column, types)
  # return original method if not using 'OracleEnhanced'
  return prepare_column_options_without_oracle_enhanced(column, types) unless oracle_enhanced_adapter?

  spec = {}
  spec[:name]      = column.name.inspect
  spec[:type]      = column.virtual? ? 'virtual' : column.type.to_s
  spec[:virtual_type] = column.type.inspect if column.virtual? && column.sql_type != 'NUMBER'
  spec[:limit]     = column.limit.inspect if column.limit != types[column.type][:limit] && column.type != :decimal
  spec[:precision] = column.precision.inspect if !column.precision.nil?
  spec[:scale]     = column.scale.inspect if !column.scale.nil?
  spec[:null]      = 'false' if !column.null
  spec[:as]        = column.virtual_column_data_default if column.virtual?
  spec[:default]   = schema_default(column) if column.has_default? && !column.virtual?
  spec.delete(:default) if spec[:default].nil?
  spec
end