123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::Coders::YAMLColumn::SafeCoder

Relationships & Source Files
Inherits: Object
Defined in: activerecord/lib/active_record/coders/yaml_column.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(permitted_classes: [], unsafe_load: nil) ⇒ SafeCoder

[ GitHub ]

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

def initialize(permitted_classes: [], unsafe_load: nil)
  @permitted_classes = permitted_classes
  @unsafe_load = unsafe_load
end

Instance Method Details

#dump(object)

See additional method definition at line 15.

[ GitHub ]

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

def dump(object)
  if @unsafe_load.nil? ? ActiveRecord.use_yaml_unsafe_load : @unsafe_load
    ::YAML.dump(object)
  else
    ::YAML.safe_dump(
      object,
      permitted_classes: @permitted_classes + ActiveRecord.yaml_column_permitted_classes,
      aliases: true,
    )
  end
end

#load(payload)

See additional method definition at line 33.

[ GitHub ]

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

def load(payload)
  if @unsafe_load.nil? ? ActiveRecord.use_yaml_unsafe_load : @unsafe_load
    YAML.unsafe_load(payload)
  else
    YAML.safe_load(
      payload,
      permitted_classes: @permitted_classes + ActiveRecord.yaml_column_permitted_classes,
      aliases: true,
    )
  end
end