Class: ActiveRecord::ConnectionAdapters::NuoDBColumn

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, default, sql_type = nil, null = true, length = nil, precision = nil, scale = nil, options = {}) ⇒ NuoDBColumn

Returns a new instance of NuoDBColumn.

[View source]

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 61

def initialize(name, default, sql_type = nil, null = true, length = nil, precision = nil, scale = nil, options = {})
  @options = options.symbolize_keys

  @name      = name
  @null      = null

  # NuoDB stores fixed point decimal values as 'bigint'
  # Examine the scale to determine the type
  if precision > 0 && sql_type == 'bigint'
    @sql_type  = 'decimal'
    @type      = :decimal
    @precision = precision
    @scale     = scale
  else
    @sql_type  = sql_type
    @type      = simplified_type(sql_type)
    @precision = nil
    @scale     = nil
  end

  # Limit only applies to :string, :text, :binary, and :integer
  # See http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html
  if @type =~ /^(string|text|binary|integer)$/ && @sql_type != 'string'
    @limit     = length
  else
    @limit     = nil
  end

  @default   = extract_default(default)
  @primary   = @options[:is_identity] || @options[:is_primary]
  @coder     = nil
end

Class Method Details

.binary_to_string(value) ⇒ Object

[View source]

100
101
102
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 100

def binary_to_string(value)
  value =~ /[^[:xdigit:]]/ ? value : [value].pack('H*')
end

.string_to_binary(value) ⇒ Object

[View source]

96
97
98
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 96

def string_to_binary(value)
  "0x#{value.unpack("H*")[0]}"
end

Instance Method Details

#default_functionObject

[View source]

134
135
136
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 134

def default_function
  @options[:default_function]
end

#is_identity?Boolean

Returns:

  • (Boolean)
[View source]

106
107
108
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 106

def is_identity?
  @options[:is_identity]
end

#is_integer?Boolean

Returns:

  • (Boolean)
[View source]

118
119
120
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 118

def is_integer?
  !!(@sql_type =~ /int/i)
end

#is_primary?Boolean

Returns:

  • (Boolean)
[View source]

110
111
112
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 110

def is_primary?
  @options[:is_primary]
end

#is_real?Boolean

Returns:

  • (Boolean)
[View source]

122
123
124
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 122

def is_real?
  !!(@sql_type =~ /real/i)
end

#is_utf8?Boolean

Returns:

  • (Boolean)
[View source]

114
115
116
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 114

def is_utf8?
  !!(@sql_type =~ /nvarchar|ntext|nchar/i)
end

#sql_type_for_statementObject

[View source]

126
127
128
129
130
131
132
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 126

def sql_type_for_statement
  if is_integer? || is_real?
    sql_type.sub(/\((\d+)?\)/, '')
  else
    sql_type
  end
end

#table_klassObject

[View source]

142
143
144
145
146
147
148
149
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 142

def table_klass
  @table_klass ||= begin
    table_name.classify.constantize
  rescue StandardError, NameError, LoadError
    nil
  end
  (@table_klass && @table_klass < ActiveRecord::Base) ? @table_klass : nil
end

#table_nameObject

[View source]

138
139
140
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 138

def table_name
  @options[:table_name]
end