Class: ActiveRecord::ConnectionAdapters::OracleEnhancedColumn

Inherits:
Column
  • Object
show all
Defined in:
lib/active_record/connection_adapters/oracle_enhanced_column.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, default, sql_type = nil, null = true, table_name = nil, forced_column_type = nil, virtual = false) ⇒ OracleEnhancedColumn

:nodoc:



7
8
9
10
11
12
13
14
15
16
# File 'lib/active_record/connection_adapters/oracle_enhanced_column.rb', line 7

def initialize(name, default, sql_type = nil, null = true, table_name = nil, forced_column_type = nil, virtual=false) #:nodoc:
  @table_name = table_name
  @forced_column_type = forced_column_type
  @virtual = virtual
  super(name, default, sql_type, null)
  @virtual_column_data_default = default.inspect if virtual
  # Is column NCHAR or NVARCHAR2 (will need to use N'...' value quoting for these data types)?
  # Define only when needed as adapter "quote" method will check at first if instance variable is defined.
  @nchar = true if @type == :string && sql_type[0,1] == 'N'
end

Instance Attribute Details

#forced_column_typeObject (readonly)

:nodoc:



5
6
7
# File 'lib/active_record/connection_adapters/oracle_enhanced_column.rb', line 5

def forced_column_type
  @forced_column_type
end

#ncharObject (readonly)

:nodoc:



5
6
7
# File 'lib/active_record/connection_adapters/oracle_enhanced_column.rb', line 5

def nchar
  @nchar
end

#table_nameObject (readonly)

:nodoc:



5
6
7
# File 'lib/active_record/connection_adapters/oracle_enhanced_column.rb', line 5

def table_name
  @table_name
end

#virtual_column_data_defaultObject (readonly)

:nodoc:



5
6
7
# File 'lib/active_record/connection_adapters/oracle_enhanced_column.rb', line 5

def virtual_column_data_default
  @virtual_column_data_default
end

Class Method Details

.string_to_date(string) ⇒ Object

convert Time or DateTime value to Date for :date columns



41
42
43
44
# File 'lib/active_record/connection_adapters/oracle_enhanced_column.rb', line 41

def self.string_to_date(string) #:nodoc:
  return string.to_date if string.is_a?(Time) || string.is_a?(DateTime)
  super
end

.string_to_raw(string) ⇒ Object

convert RAW column values back to byte strings.



53
54
55
# File 'lib/active_record/connection_adapters/oracle_enhanced_column.rb', line 53

def self.string_to_raw(string) #:nodoc:
  string
end

.string_to_time(string) ⇒ Object

convert Date value to Time for :datetime columns



47
48
49
50
# File 'lib/active_record/connection_adapters/oracle_enhanced_column.rb', line 47

def self.string_to_time(string) #:nodoc:
  return string.to_time if string.is_a?(Date) && !OracleEnhancedAdapter.emulate_dates
  super
end

.value_to_boolean(value) ⇒ Object

convert something to a boolean added y as boolean value



30
31
32
33
34
35
36
37
38
# File 'lib/active_record/connection_adapters/oracle_enhanced_column.rb', line 30

def self.value_to_boolean(value) #:nodoc:
  if value == true || value == false
    value
  elsif value.is_a?(String) && value.blank?
    nil
  else
    %w(true t 1 y +).include?(value.to_s.downcase)
  end
end

Instance Method Details

#commentObject

Get column comment from schema definition. Will work only if using default ActiveRecord connection.



59
60
61
# File 'lib/active_record/connection_adapters/oracle_enhanced_column.rb', line 59

def comment
  ActiveRecord::Base.connection.column_comment(@table_name, name)
end

#type_cast(value) ⇒ Object

:nodoc:



18
19
20
21
22
# File 'lib/active_record/connection_adapters/oracle_enhanced_column.rb', line 18

def type_cast(value) #:nodoc:
  return OracleEnhancedColumn::string_to_raw(value) if type == :raw
  return guess_date_or_time(value) if type == :datetime && OracleEnhancedAdapter.emulate_dates
  super
end

#virtual?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/active_record/connection_adapters/oracle_enhanced_column.rb', line 24

def virtual?
  @virtual
end