Class: PikoTransaction::DeleteCommand

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/piko_transaction/delete_command.rb

Instance Method Summary collapse

Methods included from Logger

#logger

Constructor Details

#initialize(document_id, collection, &success_action) ⇒ DeleteCommand

Returns a new instance of DeleteCommand.



26
27
28
29
30
31
32
33
34
35
# File 'lib/piko_transaction/delete_command.rb', line 26

def initialize(document_id, collection, &success_action)
  @name = nil
  @document_id = document_id
  @collection = collection
  @success_action = success_action
  @success_callbacks = []
  @failure_callbacks = []
  @deleted_doc = nil
  @done = false
end

Instance Method Details

#add_failure_callback(callback) ⇒ Object



59
60
61
62
# File 'lib/piko_transaction/delete_command.rb', line 59

def add_failure_callback(callback)
  @failure_callbacks << callback if callback.respond_to?(:call)
  logger.debug { format "%s Registered failure callbacks: %s", to_s, @failure_callbacks.count }
end

#add_success_callback(callback) ⇒ Object



54
55
56
57
# File 'lib/piko_transaction/delete_command.rb', line 54

def add_success_callback(callback)
  @success_callbacks << callback if callback.respond_to?(:call)
  logger.debug { format "%s Registered success callbacks: %s", to_s, @success_callbacks.count }
end

#doObject



37
38
39
40
# File 'lib/piko_transaction/delete_command.rb', line 37

def do
  add_success_callback @success_action
  remove_document ? call_success_callbacks : call_failure_callbacks
end

#name(value) ⇒ Object



50
51
52
# File 'lib/piko_transaction/delete_command.rb', line 50

def name(value)
  @name = value.to_s
end

#to_sObject



46
47
48
# File 'lib/piko_transaction/delete_command.rb', line 46

def to_s
  format "[%s]", @name || "delete_cmd"
end

#undoObject



42
43
44
# File 'lib/piko_transaction/delete_command.rb', line 42

def undo
  store_document
end