Class: ActiveRecord::Coders::YAMLColumn

Inherits:
ColumnSerializer show all
Defined in:
lib/active_record/coders/yaml_column.rb

Overview

:nodoc:

Defined Under Namespace

Classes: SafeCoder

Instance Attribute Summary

Attributes inherited from ColumnSerializer

#object_class

Instance Method Summary collapse

Methods inherited from ColumnSerializer

#assert_valid_value, #dump, #load

Constructor Details

#initialize(attr_name, object_class = Object, permitted_classes: [], unsafe_load: nil) ⇒ YAMLColumn

Returns a new instance of YAMLColumn.



59
60
61
62
63
64
65
66
# File '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

#coderObject



77
78
79
80
81
82
83
84
85
# File '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) ⇒ Object

:nodoc:



68
69
70
71
72
73
74
75
# File '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