Class: PsychShield

Inherits:
Object
  • Object
show all
Defined in:
lib/psych_shield.rb

Defined Under Namespace

Classes: DeniedObject

Constant Summary collapse

@@allowed_objects =

Generally regarded as safe for YAML loads

%W{
  Hash Array String Range
  Numeric Fixnum Integer Bignum Float Rational Complex
  Time DateTime
  NilClass TrueClass FalseClass
}
@@callback =
nil

Class Method Summary collapse

Class Method Details

.add(name) ⇒ Object



24
25
26
# File 'lib/psych_shield.rb', line 24

def self.add(name)
  @@allowed_objects << name
end

.allowed?(o) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
# File 'lib/psych_shield.rb', line 36

def self.allowed?(o)
  res = @@allowed_objects.include?(o.to_s)
  @@callback.call(o.to_s, res) if @@callback
  res
end

.callback=(cb) ⇒ Object



42
43
44
# File 'lib/psych_shield.rb', line 42

def self.callback=(cb)
  @@callback = cb
end

.clearObject



32
33
34
# File 'lib/psych_shield.rb', line 32

def self.clear
  @@allowed_objects = []
end

.remove(name) ⇒ Object



28
29
30
# File 'lib/psych_shield.rb', line 28

def self.remove(name)
  @@allowed_objects.delete(name)
end