Class: ActiveRecord::Type::Serialized
- Inherits:
 - 
      ActiveModel::Type::Value
      
        
- Object
 - ActiveModel::Type::Value
 - ActiveRecord::Type::Serialized
 
 
- Includes:
 - ActiveModel::Type::Helpers::Mutable
 
- Defined in:
 - activerecord/lib/active_record/type/serialized.rb
 
Overview
:nodoc:
Instance Attribute Summary collapse
- 
  
    
      #coder  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute coder.
 - 
  
    
      #subtype  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute subtype.
 
Attributes inherited from ActiveModel::Type::Value
Instance Method Summary collapse
- #accessor ⇒ Object
 - #assert_valid_value(value) ⇒ Object
 - #changed_in_place?(raw_old_value, value) ⇒ Boolean
 - #deserialize(value) ⇒ Object
 - #force_equality?(value) ⇒ Boolean
 - 
  
    
      #initialize(subtype, coder)  ⇒ Serialized 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Serialized.
 - #serialize(value) ⇒ Object
 - 
  
    
      #serialized?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
:nodoc:.
 
Methods included from ActiveModel::Type::Helpers::Mutable
Methods inherited from ActiveModel::Type::Value
#==, #as_json, #binary?, #cast, #changed?, #hash, #map, #mutable?, #serializable?, #type, #type_cast_for_schema, #value_constructed_by_mass_assignment?
Methods included from ActiveModel::Type::SerializeCastValue
included, #itself_if_serialize_cast_value_compatible, serialize
Methods included from ActiveSupport::Concern
#append_features, #class_methods, extended, #included, #prepend_features, #prepended
Constructor Details
#initialize(subtype, coder) ⇒ Serialized
Returns a new instance of Serialized.
      12 13 14 15 16  | 
    
      # File 'activerecord/lib/active_record/type/serialized.rb', line 12 def initialize(subtype, coder) @subtype = subtype @coder = coder super(subtype) end  | 
  
Instance Attribute Details
#coder ⇒ Object (readonly)
Returns the value of attribute coder.
      10 11 12  | 
    
      # File 'activerecord/lib/active_record/type/serialized.rb', line 10 def coder @coder end  | 
  
#subtype ⇒ Object (readonly)
Returns the value of attribute subtype.
      10 11 12  | 
    
      # File 'activerecord/lib/active_record/type/serialized.rb', line 10 def subtype @subtype end  | 
  
Instance Method Details
#accessor ⇒ Object
      42 43 44  | 
    
      # File 'activerecord/lib/active_record/type/serialized.rb', line 42 def accessor ActiveRecord::Store::IndifferentHashAccessor end  | 
  
#assert_valid_value(value) ⇒ Object
      46 47 48 49 50  | 
    
      # File 'activerecord/lib/active_record/type/serialized.rb', line 46 def assert_valid_value(value) if coder.respond_to?(:assert_valid_value) coder.assert_valid_value(value, action: "serialize") end end  | 
  
#changed_in_place?(raw_old_value, value) ⇒ Boolean
      35 36 37 38 39 40  | 
    
      # File 'activerecord/lib/active_record/type/serialized.rb', line 35 def changed_in_place?(raw_old_value, value) return false if value.nil? raw_new_value = encoded(value) raw_old_value.nil? != raw_new_value.nil? || subtype.changed_in_place?(raw_old_value, raw_new_value) end  | 
  
#deserialize(value) ⇒ Object
      18 19 20 21 22 23 24  | 
    
      # File 'activerecord/lib/active_record/type/serialized.rb', line 18 def deserialize(value) if default_value?(value) value else coder.load(super) end end  | 
  
#force_equality?(value) ⇒ Boolean
      52 53 54  | 
    
      # File 'activerecord/lib/active_record/type/serialized.rb', line 52 def force_equality?(value) coder.respond_to?(:object_class) && value.is_a?(coder.object_class) end  | 
  
#serialize(value) ⇒ Object
      26 27 28 29 30 31  | 
    
      # File 'activerecord/lib/active_record/type/serialized.rb', line 26 def serialize(value) return if value.nil? unless default_value?(value) super coder.dump(value) end end  | 
  
#serialized? ⇒ Boolean
:nodoc:
      56 57 58  | 
    
      # File 'activerecord/lib/active_record/type/serialized.rb', line 56 def serialized? # :nodoc: true end  |