Module: JSON

Defined in:
lib/json/merge_patch/version.rb,
lib/json/merge_patch.rb,
lib/json/merge_patch/railtie.rb

Overview

The Ruby standard Library exports JSON www.ruby-doc.org/stdlib-1.9.3/libdoc/json/rdoc/

Defined Under Namespace

Classes: MergePatch

Constant Summary collapse

MergeError =

This represents an error that occurs during merging.

Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.merge(document, merge_patch) ⇒ String

Merges a patch into the existing JSON document.

Parameters:

  • document (String)

    the original JSON document.

  • merge_patch (Symbol)

    the merge-patch JSON document.

Returns:

  • (String)

    the final document after applying the patch



15
16
17
18
19
20
21
# File 'lib/json/merge_patch.rb', line 15

def self.merge(document, merge_patch)
  orig = JSON.parse(document)
  patch = JSON.parse(merge_patch)
  JSON.dump(MergePatch.new(orig, patch).call)
rescue
  raise MergeError
end