Class: ActiveRecord::ConnectionAdapters::JdbcColumn

Inherits:
Column
  • Object
show all
Defined in:
lib/arjdbc/jdbc/column.rb

Overview

The base class for all of JdbcAdapter's returned columns. Instances of JdbcColumn will get extended with "column-spec" modules (similar to how JdbcAdapter gets spec modules in) if the adapter spec module provided a column_selector (matcher) method for it's database specific type.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, name, *args) ⇒ JdbcColumn

Returns a new instance of JdbcColumn.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/arjdbc/jdbc/column.rb', line 15

def initialize(config, name, *args)
  if self.class == JdbcColumn
    # NOTE: extending classes do not want this if they do they shall call
    call_discovered_column_callbacks(config) if config
    default = args.shift
  else # for extending classes allow ignoring first argument :
    if ! config.nil? && ! config.is_a?(Hash)
      default = name; name = config # initialize(name, default, *args)
    else
      default = args.shift
    end
  end
  # super <= 4.1: (name, default, sql_type = nil, null = true)
  # super >= 4.2: (name, default, cast_type, sql_type = nil, null = true)
  super(name, default_value(default), *args)
  init_column(name, default, *args)
end

Instance Attribute Details

#limit=(value) ⇒ Object (writeonly)

Sets the attribute limit

Parameters:

  • value

    the value to set the attribute limit to.



13
14
15
# File 'lib/arjdbc/jdbc/column.rb', line 13

def limit=(value)
  @limit = value
end

#precision=(value) ⇒ Object (writeonly)

Sets the attribute precision

Parameters:

  • value

    the value to set the attribute precision to.



13
14
15
# File 'lib/arjdbc/jdbc/column.rb', line 13

def precision=(value)
  @precision = value
end

Class Method Details

.column_typesHash

Returns the available column types

Returns:

  • (Hash)

    of (matcher, block) pairs



54
55
56
57
58
59
60
61
62
63
# File 'lib/arjdbc/jdbc/column.rb', line 54

def self.column_types
  types = {}
  for mod in ::ArJdbc.modules
    if mod.respond_to?(:column_selector)
      sel = mod.column_selector # [ matcher, block ]
      types[ sel[0] ] = sel[1]
    end
  end
  types
end

Instance Method Details

#default_value(value) ⇒ Object

Similar to ActiveRecord's extract_value_from_default(default).

Returns:

  • default value for a given column



38
# File 'lib/arjdbc/jdbc/column.rb', line 38

def default_value(value); value; end

#init_column(*args) ⇒ Object

Additional column initialization for sub-classes.



34
# File 'lib/arjdbc/jdbc/column.rb', line 34

def init_column(*args); end