Class: Lines::Dumper

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

Overview

Some opinions here as well on the format:

We really want to never fail at dumping because you know, they’re logs. It’s better to get a slightly less readable log that no logs at all.

We’re trying to be helpful for humans. It means that if possible we want to make things shorter and more readable. It also means that ideally we would like the parsing to be isomorphic but approximations are alright. For example a symbol might become a string.

Basically, values are either composite (dictionaries and arrays), quoted strings or litterals. Litterals are strings that can be parsed to something else depending if the language supports it or not. Litterals never contain white-spaces or other weird (very precise !) characters.

the true litteral is written as “#t” the false litteral is written as “#f” the nil / null litteral is written as “nil”

dictionary keys are always strings or litterals.

Pleaaase, keep units with numbers. And we provide a way for this: a tuple of (number, litteral) can be concatenated. Eg: (3, ‘ms’) => 3ms alternatively if your language supports a time range it could be serialized to the same value (and parsed back as well).

if we don’t know how to serialize something we provide a language-specific string of it and encode is at such.

The output ought to use the UTF-8 encoding.

This dumper has been inspired by the OkJSON gem (both formats look alike after all).

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#max_depthObject

Returns the value of attribute max_depth.



242
243
244
# File 'lib/lines.rb', line 242

def max_depth
  @max_depth
end

Instance Method Details

#dump(obj) ⇒ Object

> String



233
234
235
# File 'lib/lines.rb', line 233

def dump(obj) #=> String
  objenc_internal(obj)
end

#map(klass, &rule) ⇒ Object

Used to introduce new ruby litterals.



238
239
240
# File 'lib/lines.rb', line 238

def map(klass, &rule)
  @mapping[klass] = rule
end