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



109
110
111
# File 'lib/fauna/objects.rb', line 109

def initialize(bytes)
  self.bytes = bytes
end

Instance Attribute Details

#bytesObject

The raw bytes.



101
102
103
# File 'lib/fauna/objects.rb', line 101

def bytes
  @bytes
end

Class Method Details

.from_base64(enc) ⇒ Object

Create new Bytes object from Base64 encoded bytes.



127
128
129
# File 'lib/fauna/objects.rb', line 127

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.



119
120
121
122
# File 'lib/fauna/objects.rb', line 119

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

#to_hashObject

Converts the Bytes to Hash form.



114
115
116
# File 'lib/fauna/objects.rb', line 114

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