Class: Parse::Model

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Callbacks, ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Dirty, ActiveModel::Model, ActiveModel::Serializers::JSON, Client::Connectable
Defined in:
lib/parse/model/model.rb,
lib/parse/model/core/builder.rb

Overview

The core model of all Parse-Stack classes. This class works by providing a baseline for all subclass objects to support ActiveModel features such as serialization, dirty tracking, callbacks, etc.

See Also:

  • ActiveModel

Direct Known Subclasses

Bytes, File, GeoPoint, Pointer

Defined Under Namespace

Classes: Builder

Constant Summary collapse

TYPE_FIELD =

The name of the field in a hash that contains information about the type of data the hash represents.

'__type'.freeze
OBJECT_ID =

The objectId field in Parse Objects.

'objectId'.freeze
ID =

See Also:

"id".freeze
KEY_CLASS_NAME =

The key field for getting class information.

'className'.freeze
KEY_OBJECT_ID =
Deprecated.

Use OBJECT_ID instead.

'objectId'.freeze
KEY_CREATED_AT =

The key field for getting the created at date of an object hash.

'createdAt'
KEY_UPDATED_AT =

The key field for getting the updated at date of an object hash.

'updatedAt'
CLASS_USER =

The collection for Users in Parse. Used by Parse::User.

'_User'
CLASS_INSTALLATION =

The collection for Installations in Parse. Used by Parse::Installation.

'_Installation'
CLASS_SESSION =

The collection for revocable Sessions in Parse. Used by Parse::Session.

'_Session'
CLASS_ROLE =

The collection for Roles in Parse. Used by Parse::Role.

'_Role'
CLASS_PRODUCT =

The collection for to store Products (in-App purchases) in Parse. Used by Parse::Product.

'_Product'
TYPE_FILE =

The type label for hashes containing file data. Used by Parse::File.

'File'
TYPE_GEOPOINT =

The type label for hashes containing geopoints. Used by Parse::GeoPoint.

'GeoPoint'
TYPE_OBJECT =

The type label for hashes containing a Parse object. Used by Parse::Object and subclasses.

'Object'
TYPE_DATE =

The type label for hashes containing a Parse date object. Used by Parse::Date.

'Date'
TYPE_BYTES =

The type label for hashes containing 'byte' data. Used by Parse::Bytes.

'Bytes'
TYPE_ACL =

The type label for hashes containing ACL data. Used by Parse::ACL

'ACL'
TYPE_NUMBER =

The type label for hashes storing numeric data.

'Number'
TYPE_POINTER =

The type label for hashes containing a Parse pointer.

'Pointer'
TYPE_RELATION =

The type label for hashes representing relational data.

'Relation'

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Client::Connectable

#client

Class Attribute Details

.raise_on_save_failureBoolean

By default, we return `true` or `false` for save and destroy operations. If you prefer to have `Parse::Object` raise an exception instead, you can tell to do so either globally or on a per-model basis. When a save fails, it will raise a `Parse::RecordNotSaved`.

When enabled, if an error is returned by Parse due to saving or destroying a record, due to your `before_save` or `before_delete` validation cloud code triggers, `Parse::Object` will return the a `Parse::RecordNotSaved` exception type. This exception has an instance method of `#object` which contains the object that failed to save.

Examples:

Parse::Model.raise_on_save_failure = true # globally across all models
Song.raise_on_save_failure = true          # per-model

# or per-instance raise on failure
song.save!

Returns:

  • (Boolean)

111
112
113
# File 'lib/parse/model/model.rb', line 111

def raise_on_save_failure
  @global_raise_on_save_failure ||= false
end

Class Method Details

.find_class(str) ⇒ Parse::Object

Find a Parse::Model subclass matching this type or Pares collection name. This helper method is useful to find the corresponding class ruby Parse::Object subclass that handles the provided parse class.

Examples:

Parse::Model.find_class('_User') # => Parse::User
Parse::Model.find_class('_Date') # => Parse::Date
Parse::Model.find_class('Installation') # => Parse::Installation

class Artist < Parse::Object
  parse_class "Musician"
end

Parse::Model.find_class("Musician") # => Artist

Parameters:

  • str (String)

    the class name

Returns:

  • (Parse::Object)

    a Parse::Object subclass or a specific Parse type.


138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/parse/model/model.rb', line 138

def self.find_class(str)
  return Parse::File if str == TYPE_FILE
  return Parse::GeoPoint if str == TYPE_GEOPOINT
  return Parse::Date if str == TYPE_DATE
  return Parse::Bytes if str == TYPE_BYTES
  # return Parse::User if str == "User"
  # return Parse::Installation if str == "Installation"

  str = str.to_s
  # Basically go through all Parse::Object subclasses and see who is has a parse_class
  # set to this string. We will cache the results for future use.
  @@model_cache[str] ||= Parse::Object.descendants.find do |f|
    f.parse_class == str || f.parse_class == "_#{str}"
  end

end