Class: Parse::DataType

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, ActiveModel::Serializers::JSON
Defined in:
lib/parse/model/acl.rb

Overview

This class allows you to define custom data types for your model fields. You can define a subclass that implements the DataType.typecast method to convert to and from a value for serialization. The ACL class is implemented in this fashion.

Direct Known Subclasses

ACL

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.typecast(value, **opts) ⇒ Object

Transform an incoming value to another. The default implementation does returns the original value. This method should return an instance of a DataType subclass.

Parameters:

  • value (Object)

    the input value to be typecasted.

  • opts (Hash)

    a set of options to be used when typecasting.

Returns:


26
27
28
# File 'lib/parse/model/acl.rb', line 26

def self.typecast(value, **opts)
  value
end

Instance Method Details

#as_json(*args) ⇒ Hash

Serialize this DataType into an JSON object hash format to be saved to Parse. The default implementation returns an empty hash.

Returns:


33
34
35
# File 'lib/parse/model/acl.rb', line 33

def as_json(*args)
  {}.as_json
end

#attributesHash

Returns the set of attributes for this data type.

Returns:

  • (Hash)

    the set of attributes for this data type.


16
17
18
# File 'lib/parse/model/acl.rb', line 16

def attributes
  {}
end