Class: Console::Format::Safe

Inherits:
Object
  • Object
show all
Defined in:
lib/console/format/safe.rb

Overview

This class is used to safely dump objects. It will attempt to dump the object using the given format, but if it fails, it will generate a safe version of the object.

Instance Method Summary collapse

Constructor Details

#initialize(format: ::JSON, limit: 8, encoding: ::Encoding::UTF_8) ⇒ Safe

Returns a new instance of Safe.



13
14
15
16
17
# File 'lib/console/format/safe.rb', line 13

def initialize(format: ::JSON, limit: 8, encoding: ::Encoding::UTF_8)
	@format = format
	@limit = limit
	@encoding = encoding
end

Instance Method Details

#dump(object) ⇒ Object



19
20
21
22
23
# File 'lib/console/format/safe.rb', line 19

def dump(object)
	@format.dump(object, @limit)
rescue SystemStackError, StandardError => error
	@format.dump(safe_dump(object, error))
end