Class: ActiveRecord::TypeCaster::Connection
- Defined in:
 - activerecord/lib/active_record/type_caster/connection.rb
 
Overview
:nodoc:
Instance Method Summary collapse
- 
  
    
      #initialize(klass, table_name)  ⇒ Connection 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Connection.
 - #type_cast_for_database(attr_name, value) ⇒ Object
 - #type_for_attribute(attr_name) ⇒ Object
 
Constructor Details
#initialize(klass, table_name) ⇒ Connection
Returns a new instance of Connection.
      6 7 8 9  | 
    
      # File 'activerecord/lib/active_record/type_caster/connection.rb', line 6 def initialize(klass, table_name) @klass = klass @table_name = table_name end  | 
  
Instance Method Details
#type_cast_for_database(attr_name, value) ⇒ Object
      11 12 13 14  | 
    
      # File 'activerecord/lib/active_record/type_caster/connection.rb', line 11 def type_cast_for_database(attr_name, value) type = type_for_attribute(attr_name) type.serialize(value) end  | 
  
#type_for_attribute(attr_name) ⇒ Object
      16 17 18 19 20 21 22 23 24 25 26 27  | 
    
      # File 'activerecord/lib/active_record/type_caster/connection.rb', line 16 def type_for_attribute(attr_name) schema_cache = @klass.schema_cache if schema_cache.data_source_exists?(table_name) column = schema_cache.columns_hash(table_name)[attr_name.to_s] if column type = @klass.with_connection { |connection| connection.lookup_cast_type_from_column(column) } end end type || Type.default_value end  |