Class: ActiveRecord::ConnectionAdapters::FbColumn

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

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, default, cast_type, sql_type = nil, null = true, fb_options = {}) ⇒ FbColumn

Returns a new instance of FbColumn.



31
32
33
34
# File 'lib/active_record/connection_adapters/fb_column.rb', line 31

def initialize(name, default, sql_type = nil, null = true, fb_options = {})
  @domain, @sub_type = fb_options.values_at(:domain, :sub_type)
  super(name.downcase, parse_default(default), sql_type, null)
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



28
29
30
# File 'lib/active_record/connection_adapters/fb_column.rb', line 28

def domain
  @domain
end

#sub_typeObject (readonly)

Returns the value of attribute sub_type.



28
29
30
# File 'lib/active_record/connection_adapters/fb_column.rb', line 28

def sub_type
  @sub_type
end

Class Method Details

.sql_type_for(field) ⇒ Object

When detecting types, ActiveRecord expects strings in a certain format. In 4.2, these strings are converted to ActiveRecord::Type::Value objects using the type_map (see #initialize_type_map). Prior to 4.2, the sql_type could be coerced to a certain ActiveRecord type in Column#simplified_type.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/active_record/connection_adapters/fb_column.rb', line 11

def sql_type_for(field)
  type, sub_type, domain = field.values_at(:type, :sub_type, :domain)
  sql_type = ::Fb::SqlType.from_code(type, sub_type || 0).downcase

  case sql_type
  when /(numeric|decimal)/
    sql_type << "(#{field[:precision]},#{field[:scale].abs})"
  when /(int|float|double|char|varchar)/
    sql_type << "(#{field[:limit]})"
  end

  sql_type << ' sub_type text' if sql_type =~ /blob/ && sub_type == 1
  sql_type = 'boolean' if domain =~ %r(#{boolean_domain[:name]})i
  sql_type
end