Module: Parse::Core::Fetching

Included in:
Object
Defined in:
lib/parse/model/core/fetching.rb

Overview

Defines the record fetching interface for instances of Parse::Object.

Instance Method Summary collapse

Instance Method Details

#autofetch!(key) ⇒ Boolean

Autofetches the object based on a key that is not part Properties::BASE_KEYS. If the key is not a Parse standard key, and the current object is in a Pointer state, then fetch the data related to this record from the Parse data store.

Parameters:

  • key (String)

    the name of the attribute being accessed.

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
# File 'lib/parse/model/core/fetching.rb', line 42

def autofetch!(key)
  key = key.to_sym
  @fetch_lock ||= false
  if @fetch_lock != true && pointer? && key != :acl && Parse::Properties::BASE_KEYS.include?(key) == false && respond_to?(:fetch)
    #puts "AutoFetching Triggerd by: #{self.class}.#{key} (#{id})"
    @fetch_lock = true
    send :fetch
    @fetch_lock = false
  end
end

#fetchself

Fetches the object from the Parse data store if the object is in a Pointer state. This is similar to the `fetchIfNeeded` action in the standard Parse client SDK.

Returns:

  • (self)

    the current object.



31
32
33
34
# File 'lib/parse/model/core/fetching.rb', line 31

def fetch
  # if it is a pointer, then let's go fetch the rest of the content
  pointer? ? fetch! : self
end

#fetch!(opts = {}) ⇒ self

Force fetches and updates the current object with the data contained in the Parse collection. The changes applied to the object are not dirty tracked.

Parameters:

  • opts (Hash) (defaults to: {})

    a set of options to pass to the client request.

Returns:

  • (self)

    the current object, useful for chaining.



17
18
19
20
21
22
23
24
25
26
# File 'lib/parse/model/core/fetching.rb', line 17

def fetch!(opts = {})
  response = client.fetch_object(parse_class, id, opts)
  if response.error?
    puts "[Fetch Error] #{response.code}: #{response.error}"
  end
  # take the result hash and apply it to the attributes.
  apply_attributes!(response.result, dirty_track: false)
  clear_changes!
  self
end