Module: SchemaPlus::ActiveRecord::ConnectionAdapters::PostgreSQLColumn

Defined in:
lib/schema_plus/active_record/connection_adapters/postgresql_adapter.rb

Overview

PostgreSQL-specific extensions to column definitions in a table.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Extracts the value from a PostgreSQL column default definition.


7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/schema_plus/active_record/connection_adapters/postgresql_adapter.rb', line 7

def self.included(base) #:nodoc:
  base.extend ClassMethods
  if defined?(JRUBY_VERSION)
    base.alias_method_chain :default_value, :schema_plus
  else
    if "#{::ActiveRecord::VERSION::MAJOR}.#{::ActiveRecord::VERSION::MINOR}".to_r < "4.2".to_r
      base.class_eval do
        class << self
          alias_method_chain :extract_value_from_default, :schema_plus
        end
      end
    end
  end
end

Instance Method Details

#default_value_with_schema_plus(default) ⇒ Object


39
40
41
42
# File 'lib/schema_plus/active_record/connection_adapters/postgresql_adapter.rb', line 39

def default_value_with_schema_plus(default)
  value = default_value_without_schema_plus(default)
  self.class.convert_default_value(default, value)
end

#initialize(name, default, cast_type, sql_type = nil, null = true, default_function = nil) ⇒ Object


23
24
25
26
27
28
29
30
31
# File 'lib/schema_plus/active_record/connection_adapters/postgresql_adapter.rb', line 23

def initialize(name, default, sql_type = nil, null = true)
  if default.is_a? Hash
    if default[:expr]
      @default_expr = default[:expr]
    end
    default = nil
  end
  super(name, default, sql_type, null)
end