Class: JSONP3::Patch::OpTest

Inherits:
Op
  • Object
show all
Defined in:
lib/json_p3/patch/op_test.rb

Overview

The JSON Patch test operation.

Instance Method Summary collapse

Constructor Details

#initialize(pointer, value) ⇒ OpTest

Returns a new instance of OpTest.

Parameters:

  • pointer (JSONPointer)
  • value (JSON-like value)


9
10
11
12
13
# File 'lib/json_p3/patch/op_test.rb', line 9

def initialize(pointer, value)
  super()
  @pointer = pointer
  @value = value
end

Instance Method Details

#apply!(value, index) ⇒ Object



19
20
21
22
23
24
# File 'lib/json_p3/patch/op_test.rb', line 19

def apply!(value, index)
  obj = @pointer.resolve(value)
  raise JSONP3::Patch::TestFailure, "test failed (#{name}:#{index})" if obj != @value

  value
end

#nameObject



15
16
17
# File 'lib/json_p3/patch/op_test.rb', line 15

def name
  "test"
end

#to_hObject



26
27
28
# File 'lib/json_p3/patch/op_test.rb', line 26

def to_h
  { "op" => name, "path" => @pointer.to_s, "value" => @value }
end