Class: ActiveRecord::ConnectionAdapters::RedshiftColumn

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

Overview

Redshift-specific extensions to column definitions in a table.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, default, sql_type = nil, null = true, timezone = nil) ⇒ RedshiftColumn

Instantiates a new Redshift column definition in a table.



37
38
39
40
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 37

def initialize(name, default, sql_type = nil, null = true, timezone = nil)
  self.timezone = timezone
  super(name, self.class.extract_value_from_default(default), sql_type, null)
end

Class Attribute Details

.money_precisionObject

Returns the value of attribute money_precision.



67
68
69
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 67

def money_precision
  @money_precision
end

Instance Attribute Details

#timezoneObject

:nodoc:



35
36
37
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 35

def timezone
  @timezone
end

Class Method Details

.string_to_time(string) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 68

def string_to_time(string)
  return string unless String === string

  case string
  when 'infinity'  then 1.0 / 0.0
  when '-infinity' then -1.0 / 0.0
  else
    super
  end
end

.string_to_time_with_timezone(string, timezone) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 79

def string_to_time_with_timezone(string, timezone)
  if string =~ self::Format::ISO_DATETIME
    Time.parse("#{string} #{timezone}")
  else
    string_to_time(string)
  end
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  name == other.name && default == other.default && sql_type == other.sql_type && null == other.null
end

#type_cast(value) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 46

def type_cast(value)
  return nil if value.nil?
  return coder.load(value) if encoded?

  if timezone && [:datetime, :timestamp].include?(type)
    self.class.string_to_time_with_timezone(string, timezone)
  else
    super
  end
end

#type_cast_code(var_name) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 57

def type_cast_code(var_name)
  if timezone && [:datetime, :timestamp].include?(type)
    "#{self.class.name}.string_to_time_with_timezone(#{var_name},'#{timezone}')"
  else
    super
  end
end