Class: JSONPatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonpatcher.rb,
lib/jsonpatcher/dsl.rb,
lib/jsonpatcher/version.rb,
lib/jsonpatcher/array_patcher.rb,
lib/jsonpatcher/object_patcher.rb,
lib/jsonpatcher/element_patcher.rb

Defined Under Namespace

Classes: ArrayPatcher, DSL, ElementPatcher, ObjectPatcher

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ JSONPatcher

Returns a new instance of JSONPatcher.



8
9
10
# File 'lib/jsonpatcher.rb', line 8

def initialize(&block)
  @patcher = DSL.parse &block
end

Instance Method Details

#patch(json) ⇒ Object



12
13
14
15
16
# File 'lib/jsonpatcher.rb', line 12

def patch(json)
  item = JSON.parse(json)
  patched = @patcher.call(item)
  patched.to_json
end