Class: Parse::Object

Inherits:
Pointer
  • Object
show all
Defined in:
lib/parse/stack/async.rb

Overview

Additions to the Parse::Object class.

Instance Method Summary collapse

Instance Method Details

#destroy_eventually {|success| ... } ⇒ Boolean Also known as: delete_eventually

Adds support for deleting a Parse object in the background.

Examples:

object.destroy_eventually do |success|
   puts 'Deleted successfully' if success
end

Yields:

  • A block to call after the deletion has completed.

Yield Parameters:

  • success (Boolean)

    whether the save was successful.‘

Returns:

  • (Boolean)

    whether the job was enqueued.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/parse/stack/async.rb', line 92

def destroy_eventually
  block = block_given? ? Proc.new : nil
  _self = self
  Parse::Stack::Async.run do
    begin
      result = true
      _self.destroy
    rescue => e
      result = false
      puts "[DestroyEventually] Failed for object #{_self.parse_class}##{_self.id}: #{e}"
    ensure
      block.call(result) if block
      block = nil
      _self = nil
    end # begin
  end # do
end

#save_eventually {|success| ... } ⇒ Boolean

Adds support for saving a Parse object in the background.

Examples:

object.save_eventually do |success|
   puts "Saved successfully" if success
end

Yields:

  • A block to call after the save has completed.

Yield Parameters:

  • success (Boolean)

    whether the save was successful.

Returns:

  • (Boolean)

    whether the job was enqueued.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/parse/stack/async.rb', line 66

def save_eventually
  block = block_given? ? Proc.new : nil
  _self = self
  Parse::Stack::Async.run do
    begin
      result = true
      _self.save!
    rescue => e
      result = false
      puts "[SaveEventually] Failed for object #{_self.parse_class}##{_self.id}: #{e}"
    ensure
      block.call(result) if block
      block = nil
      _self = nil
    end # begin
  end # do
end