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

Version Path
ree_lib-1.0.65 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.64 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.63 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.62 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.61 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.60 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.59 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.58 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.57 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.56 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.55 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.54 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.53 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.52 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.51 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.50 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.49 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.48 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.47 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb
ree_lib-1.0.46 lib/ree_lib/packages/ree_json/package/ree_json/functions/to_json.rb