Class: Parse::Bytes

Inherits:
Model
  • Object
show all
Defined in:
lib/parse/model/bytes.rb

Overview

Support for the Bytes type in Parse

Constant Summary collapse

ATTRIBUTES =

The default attributes in a Parse Bytes hash.

{ __type: :string, base64: :string }.freeze

Constants inherited from Model

Model::CLASS_INSTALLATION, Model::CLASS_PRODUCT, Model::CLASS_ROLE, Model::CLASS_SESSION, Model::CLASS_USER, Model::ID, Model::KEY_CLASS_NAME, Model::KEY_CREATED_AT, Model::KEY_OBJECT_ID, Model::KEY_UPDATED_AT, Model::OBJECT_ID, Model::TYPE_ACL, Model::TYPE_BYTES, Model::TYPE_DATE, Model::TYPE_FIELD, Model::TYPE_FILE, Model::TYPE_GEOPOINT, Model::TYPE_NUMBER, Model::TYPE_OBJECT, Model::TYPE_POINTER, Model::TYPE_RELATION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

find_class

Methods included from Client::Connectable

#client

Constructor Details

#initialize(bytes = "") ⇒ Bytes

initialize with a base64 string or a Bytes object

Parameters:

  • bytes (String) (defaults to: "")

    The content as base64 string.



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

def initialize(bytes = "")
  @base64 = (bytes.is_a?(Bytes) ? bytes.base64 : bytes).dup
end

Instance Attribute Details

#attributesATTRIBUTES

Supports for mass assignment of values and encoding to JSON.

Returns:



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

def attributes
  ATTRIBUTES
end

#base64String

Returns the base64 string representing the content.

Returns:

  • (String)

    the base64 string representing the content



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

def base64
  @base64
end

Class Method Details

.parse_classTYPE_BYTES

Returns:



18
# File 'lib/parse/model/bytes.rb', line 18

def self.parse_class; TYPE_BYTES; end

Instance Method Details

#==(u) ⇒ Object

Two Parse::Bytes objects are equal if they have the same base64 signature



57
58
59
60
# File 'lib/parse/model/bytes.rb', line 57

def ==(u)
  return false unless u.is_a?(self.class)
  @base64 == u.base64
end

#decodedObject

Get the content as decoded base64 bytes



44
45
46
# File 'lib/parse/model/bytes.rb', line 44

def decoded
  Base64.decode64(@base64 || "")
end

#encode(str) ⇒ Object

Base64 encode and set the instance contents

Parameters:

  • str

    the string to encode



39
40
41
# File 'lib/parse/model/bytes.rb', line 39

def encode(str)
  @base64 = Base64.encode64(str)
end

#parse_classTYPE_BYTES Also known as: __type

Returns:



20
# File 'lib/parse/model/bytes.rb', line 20

def parse_class; self.class.parse_class; end