Sha256: 22dba732ab894c35311c3cb5ad34aed89ff62d199f64b02f8ba3f7c84fff8d21
Contents?: true
Size: 1 KB
Versions: 65
Compression:
Stored size: 1 KB
Contents
class ReeJson::ToJson include Ree::FnDSL fn :to_json do link 'ree_json/constants', -> { ESCAPE_MODES & DEFAULT_OPTIONS & MODES & TIME_FORMATS } end doc(<<~DOC) Dumps arbitrary object to json using specific dump mode. to_json({id: 1}) # => "{\"id\":1}" to_json({id: 1}, mode: :object) # => "{\":id\":{\"^o\":\"Object\"}}" List of all available Ksplat options could be found here: https://github.com/ohler55/oj/blob/develop/pages/Modes.md DOC contract( Any, Kwargs[ mode: Or[*MODES] ], Ksplat[ escape_mode?: Or[*ESCAPE_MODES], float_precision?: Integer, time_format?: Or[*TIME_FORMATS], use_as_json?: Bool, use_raw_json?: Bool, use_to_hash?: Bool, use_to_json?: Bool, RestKeys => Any ] => String ).throws(ArgumentError) def call(object, mode: :rails, **opts) options = DEFAULT_OPTIONS .dup .merge( opts.merge(mode: mode) ) Oj.dump(object, options) end end
Version data entries
65 entries across 65 versions & 1 rubygems