Class: Parse::Model
- Inherits:
- Object
- Object
- Parse::Model
- 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.
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 =
"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
- .raise_on_save_failure ⇒ Boolean
By default, we return `true` or `false` for save and destroy operations.
Class Method Summary collapse
- .find_class(str) ⇒ Parse::Object
Find a Parse::Model subclass matching this type or Pares collection name.
Methods included from Client::Connectable
Class Attribute Details
.raise_on_save_failure ⇒ Boolean
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.
109 110 111 | # File 'lib/parse/model/model.rb', line 109 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.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | # File 'lib/parse/model/model.rb', line 135 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 |