Sha256: 39f3eaa848b509ef3004188e9f23e5012b7ef8008d522c689ac8d2df7a104ca8

Contents?: true

Size: 625 Bytes

Versions: 54

Compression:

Stored size: 625 Bytes

Contents

class ReeJson::FromJson
  include Ree::FnDSL

  fn :from_json do
    link 'ree_json/constants', -> {
      DEFAULT_OPTIONS & MODES  & ESCAPE_MODES & TIME_FORMATS
    }
  end

  ParseJsonError = Class.new(StandardError)

  contract(
    Any,
    Kwargs[
      mode: Or[*MODES]
    ],
    Ksplat[
      symbol_keys?: Bool,
      RestKeys => Any
    ] => Hash
  ).throws(ParseJsonError)
  def call(object, mode: :rails, **opts)
    options = DEFAULT_OPTIONS
      .dup
      .merge(
        opts.merge(mode: mode)
      )

    Oj.load(object, options)
  rescue ArgumentError, EncodingError
    raise ParseJsonError.new
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

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