Class: Fauna::Bytes

Inherits:
Object
  • Object
show all
Defined in:
lib/fauna/objects.rb

Overview

A Bytes wrapper.

Reference: FaunaDB Special Types

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bytes) ⇒ Bytes

Creates a new Bytes wrapper with the given parameters.

bytes

The bytes to be wrapped by the Bytes object.

Reference: FaunaDB Special Types



111
112
113
# File 'lib/fauna/objects.rb', line 111

def initialize(bytes)
  self.bytes = bytes
end

Instance Attribute Details

#bytesObject

The raw bytes.



103
104
105
# File 'lib/fauna/objects.rb', line 103

def bytes
  @bytes
end

Class Method Details

.from_base64(enc) ⇒ Object

Create new Bytes object from Base64 encoded bytes.



129
130
131
# File 'lib/fauna/objects.rb', line 129

def self.from_base64(enc)
  new(Base64.urlsafe_decode64(enc))
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

Returns true if other is a Bytes and contains the same bytes.



121
122
123
124
# File 'lib/fauna/objects.rb', line 121

def ==(other)
  return false unless other.is_a? Bytes
  bytes == other.bytes
end

#to_hashObject

Converts the Bytes to Hash form.



116
117
118
# File 'lib/fauna/objects.rb', line 116

def to_hash
  { :@bytes => Base64.urlsafe_encode64(bytes) }
end