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.24 lib/ree_lib/packages/ree_json/package/ree_json/functions/from_json.rb
ree_lib-1.0.23 lib/ree_lib/packages/ree_json/package/ree_json/functions/from_json.rb
ree_lib-1.0.22 lib/ree_lib/packages/ree_json/package/ree_json/functions/from_json.rb
ree_lib-1.0.21 lib/ree_lib/packages/ree_json/package/ree_json/functions/from_json.rb
ree_lib-1.0.20 lib/ree_lib/packages/ree_json/package/ree_json/functions/from_json.rb
ree_lib-1.0.19 lib/ree_lib/packages/ree_json/package/ree_json/functions/from_json.rb
ree_lib-1.0.18 lib/ree_lib/packages/ree_json/package/ree_json/functions/from_json.rb
ree_lib-1.0.17 lib/ree_lib/packages/ree_json/package/ree_json/functions/from_json.rb
ree_lib-1.0.16 lib/ree_lib/packages/ree_json/package/ree_json/functions/from_json.rb
ree_lib-1.0.15 lib/ree_lib/packages/ree_json/package/ree_json/functions/from_json.rb
ree_lib-1.0.14 lib/ree_lib/packages/ree_json/package/ree_json/functions/from_json.rb
ree_lib-1.0.13 lib/ree_lib/packages/ree_json/package/ree_json/functions/from_json.rb
ree_lib-1.0.12 lib/ree_lib/packages/ree_json/package/ree_json/functions/from_json.rb
ree_lib-1.0.11 lib/ree_lib/packages/ree_json/package/ree_json/functions/from_json.rb