Class: JSON::Patch

Inherits:
Object
  • Object
show all
Defined in:
lib/json/patch.rb,
lib/json/patch/version.rb

Constant Summary collapse

VERSION =
"0.2.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hunks) ⇒ Patch

Returns a new instance of Patch.



7
8
9
# File 'lib/json/patch.rb', line 7

def initialize(hunks)
  @hunks = hunks.map {|h| Hunk.new(h)}
end

Instance Attribute Details

#hunksObject (readonly)

Returns the value of attribute hunks.



5
6
7
# File 'lib/json/patch.rb', line 5

def hunks
  @hunks
end

Instance Method Details

#apply_to(object) ⇒ Object

Apply this patch to an object

The object to be modified (which may be nested inside the object in the method signature) MUST implement #apply_patch.

#apply_patch should return true if the patch can be succesfully applied and false otherwise.

If any hunk in the patch cannot be applied successfully, the PATCH rfc dictates that the entire patch MUST not be applied. This atomicity must be handled by the #apply_patch implementation.



23
24
25
# File 'lib/json/patch.rb', line 23

def apply_to(object)
  object.apply_patch(self)# if object.respond_to?(:apply_patch)
end