Sha256: 52fc046bf32b4d0d27d2c70c87a2cd0bd81eacf6b7d7c9e7f9c91c0eaa46fb19

Contents?: true

Size: 671 Bytes

Versions: 18

Compression:

Stored size: 671 Bytes

Contents

# frozen_string_literal: true

require "oj"

module MuchRails; end

# MuchRails::JSON is an adapter for encoding and decoding JSON values.
# It uses Oj to do the work: https://github.com/ohler55/oj#-gem
module MuchRails::JSON
  InvalidError = Class.new(TypeError)

  def self.default_mode
    :strict
  end

  def self.encode(obj, **options)
    options[:mode] ||= default_mode
    ::Oj.dump(obj, options)
  end

  def self.decode(json, **options)
    options[:mode] ||= default_mode
    ::Oj.load(json, options)
  rescue ::Oj::ParseError => ex
    error = InvalidError.new("Oj::ParseError: #{ex.message}")
    error.set_backtrace(ex.backtrace)
    raise error
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
much-rails-0.4.3 lib/much-rails/json.rb
much-rails-0.4.2 lib/much-rails/json.rb
much-rails-0.4.1 lib/much-rails/json.rb
much-rails-0.4.0 lib/much-rails/json.rb
much-rails-0.3.0 lib/much-rails/json.rb
much-rails-0.2.8 lib/much-rails/json.rb
much-rails-0.2.7 lib/much-rails/json.rb
much-rails-0.2.6 lib/much-rails/json.rb
much-rails-0.2.5 lib/much-rails/json.rb
much-rails-0.2.4 lib/much-rails/json.rb
much-rails-0.2.3 lib/much-rails/json.rb
much-rails-0.2.2 lib/much-rails/json.rb
much-rails-0.2.1 lib/much-rails/json.rb
much-rails-0.2.0 lib/much-rails/json.rb
much-rails-0.1.3 lib/much-rails/json.rb
much-rails-0.1.2 lib/much-rails/json.rb
much-rails-0.1.1 lib/much-rails/json.rb
much-rails-0.1.0 lib/much-rails/json.rb