123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::Coders::YAMLColumn

Do not use. This class is for internal use only.
Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: ActiveRecord::Coders::ColumnSerializer
Defined in: activerecord/lib/active_record/coders/yaml_column.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(attr_name, object_class = Object, permitted_classes: [], unsafe_load: nil) ⇒ YAMLColumn

[ GitHub ]

  
# File 'activerecord/lib/active_record/coders/yaml_column.rb', line 59

def initialize(attr_name, object_class = Object, permitted_classes: [], unsafe_load: nil)
  super(
    attr_name,
    SafeCoder.new(permitted_classes: permitted_classes || [], unsafe_load: unsafe_load),
    object_class,
  )
  check_arity_of_constructor
end

Instance Method Details

#check_arity_of_constructor (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/coders/yaml_column.rb', line 88

def check_arity_of_constructor
  load(nil)
rescue ArgumentError
  raise ArgumentError, "Cannot serialize #{object_class}. Classes passed to `serialize` must have a 0 argument constructor."
end

#coder

[ GitHub ]

  
# File 'activerecord/lib/active_record/coders/yaml_column.rb', line 77

def coder
  # This is to retain forward compatibility when loading records serialized with Marshal
  # from a previous version of Rails.
  @coder ||= begin
    permitted_classes = defined?(@permitted_classes) ? @permitted_classes : []
    unsafe_load = defined?(@unsafe_load) && @unsafe_load.nil?
    SafeCoder.new(permitted_classes: permitted_classes, unsafe_load: unsafe_load)
  end
end

#init_with(coder)

[ GitHub ]

  
# File 'activerecord/lib/active_record/coders/yaml_column.rb', line 68

def init_with(coder) # :nodoc:
  unless coder["coder"]
    permitted_classes = coder["permitted_classes"] || []
    unsafe_load = coder["unsafe_load"] || false
    coder["coder"] = SafeCoder.new(permitted_classes: permitted_classes, unsafe_load: unsafe_load)
  end
  super(coder)
end