Class: JSONP3::OpTest

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

Overview

The JSON Patch test operation.

Instance Method Summary collapse

Constructor Details

#initialize(pointer, value) ⇒ OpTest

Returns a new instance of OpTest.

Parameters:



303
304
305
306
307
# File 'lib/json_p3/patch.rb', line 303

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

Instance Method Details

#apply(value, index) ⇒ Object



313
314
315
316
317
318
# File 'lib/json_p3/patch.rb', line 313

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

  value
end

#nameObject



309
310
311
# File 'lib/json_p3/patch.rb', line 309

def name
  "test"
end

#to_hObject



320
321
322
# File 'lib/json_p3/patch.rb', line 320

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