Class: Psych::Pure::SafeEmitter

Inherits:
Emitter
  • Object
show all
Defined in:
lib/psych/pure.rb

Overview

A safe emitter is a subclass of the emitter that restricts the types of objects that can be serialized.

Constant Summary collapse

DEFAULT_PERMITTED_CLASSES =
{
  TrueClass => true,
  FalseClass => true,
  NilClass => true,
  Integer => true,
  Float => true,
  String => true,
  Array => true,
  Hash => true,
}.compare_by_identity.freeze

Instance Method Summary collapse

Methods inherited from Emitter

#emit

Constructor Details

#initialize(io, options) ⇒ SafeEmitter

Initialize a new safe emitter with the given io and options.



4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
# File 'lib/psych/pure.rb', line 4765

def initialize(io, options)
  super(io, options)

  @permitted_classes = DEFAULT_PERMITTED_CLASSES.dup
  Array(options[:permitted_classes]).each do |klass|
    @permitted_classes[klass] = true
  end

  @permitted_symbols = {}.compare_by_identity
  Array(options[:permitted_symbols]).each do |symbol|
    @permitted_symbols[symbol] = true
  end

  @aliases = options.fetch(:aliases, false)
end