Class: Orchestrate::KeyValue::OperationSet

Inherits:
Object
  • Object
show all
Defined in:
lib/orchestrate/key_value.rb

Overview

An object which builds a set of operations for manipulating an Orchestrate::KeyValue

patch-operations collapse

patch-operations collapse

Constructor Details

#initialize(key_value, operations = []) ⇒ OperationSet

Initialize a new OperationSet object

Parameters:



340
341
342
343
# File 'lib/orchestrate/key_value.rb', line 340

def initialize(key_value, operations=[])
  @key_value = key_value
  @operations = operations
end

Instance Attribute Details

#key_valueKeyValue (readonly)

Returns The keyvalue this object will manipulate.

Returns:

  • (KeyValue)

    The keyvalue this object will manipulate.



333
334
335
# File 'lib/orchestrate/key_value.rb', line 333

def key_value
  @key_value
end

#operationsObject (readonly)

Returns operations to be performed.

Returns:

  • operations to be performed.



336
337
338
# File 'lib/orchestrate/key_value.rb', line 336

def operations
  @operations
end

Instance Method Details

#add(path, value) ⇒ Object



349
350
351
# File 'lib/orchestrate/key_value.rb', line 349

def add(path, value)
  self.class.new(key_value, operations.push({op: "add", path: "#{path}", value: value}))
end

#copy(from_path, to_path) ⇒ Object



365
366
367
# File 'lib/orchestrate/key_value.rb', line 365

def copy(from_path, to_path)
  self.class.new(key_value, operations.push({op: "copy", from: "#{from_path}", path: "#{to_path}"}))
end

#decrement(path, amount) ⇒ Object Also known as: dec



374
375
376
# File 'lib/orchestrate/key_value.rb', line 374

def decrement(path, amount)
  self.class.new(key_value, operations.push({op: "inc", path: "#{path}", value: -amount}))
end

#increment(path, amount) ⇒ Object Also known as: inc



369
370
371
# File 'lib/orchestrate/key_value.rb', line 369

def increment(path, amount)
  self.class.new(key_value, operations.push({op: "inc", path: "#{path}", value: amount}))
end

#move(from_path, to_path) ⇒ Object



361
362
363
# File 'lib/orchestrate/key_value.rb', line 361

def move(from_path, to_path)
  self.class.new(key_value, operations.push({op: "move", from: "#{from_path}", path: "#{to_path}"}))
end

#remove(path) ⇒ Object



353
354
355
# File 'lib/orchestrate/key_value.rb', line 353

def remove(path)
  self.class.new(key_value, operations.push({op: "remove", path: "#{path}"}))
end

#replace(path, value) ⇒ Object



357
358
359
# File 'lib/orchestrate/key_value.rb', line 357

def replace(path, value)
  self.class.new(key_value, operations.push({op: "replace", path: "#{path}", value: value}))
end

#test(path, value) ⇒ Object



379
380
381
# File 'lib/orchestrate/key_value.rb', line 379

def test(path, value)
  self.class.new(key_value, operations.push({op: "test", path: "#{path}", value: value}))
end

#update(ref = nil) ⇒ Object



345
346
347
# File 'lib/orchestrate/key_value.rb', line 345

def update(ref=nil)
  key_value.perform(:patch, operations, ref)
end