Class: ActiveRecord::ConnectionAdapters::PostgreSQLColumn
- Inherits:
-
Column
- Object
- Column
- ActiveRecord::ConnectionAdapters::PostgreSQLColumn
- Defined in:
- lib/activerecord-postgres-array/activerecord.rb
Instance Method Summary collapse
-
#simplified_type_with_array(field_type) ⇒ Object
Adds the array type for the column.
-
#type_cast_code_with_array(var_name) ⇒ Object
Does the type casting from array columns using String#from_postgres_array or Array#from_postgres_array.
Instance Method Details
#simplified_type_with_array(field_type) ⇒ Object
Adds the array type for the column.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/activerecord-postgres-array/activerecord.rb', line 100 def simplified_type_with_array(field_type) if field_type =~ /^numeric.+\[\]$/ :decimal_array elsif field_type =~ /character varying.*\[\]/ :string_array elsif field_type =~ /^(?:real|double precision)\[\]$/ :float_array elsif field_type =~ /timestamp.*\[\]/ :timestamp_array elsif field_type =~ /\[\]$/ field_type.gsub(/\[\]/, '_array').to_sym else simplified_type_without_array(field_type) end end |
#type_cast_code_with_array(var_name) ⇒ Object
Does the type casting from array columns using String#from_postgres_array or Array#from_postgres_array.
89 90 91 92 93 94 95 96 |
# File 'lib/activerecord-postgres-array/activerecord.rb', line 89 def type_cast_code_with_array(var_name) if type.to_s =~ /_array$/ base_type = type.to_s.gsub(/_array/, '') "#{var_name}.from_postgres_array(:#{base_type.parameterize('_')})" else type_cast_code_without_array(var_name) end end |