Class: Fauna::Ref

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

Overview

A Ref.

Reference: FaunaDB Special Types

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, class_ = nil, database = nil) ⇒ Ref

Creates a Ref object.

:call-seq:

Ref.new('prydain', Native.databases)

id: A string. class_: A Ref. database: A Ref.



19
20
21
22
23
24
25
# File 'lib/fauna/objects.rb', line 19

def initialize(id, class_ = nil, database = nil)
  fail ArgumentError.new 'id cannot be nil' if id.nil?

  @id = id
  @class_ = class_ unless class_.nil?
  @database = database unless database.nil?
end

Instance Attribute Details

#class_Object

The raw attributes of ref.



8
9
10
# File 'lib/fauna/objects.rb', line 8

def class_
  @class_
end

#databaseObject

The raw attributes of ref.



8
9
10
# File 'lib/fauna/objects.rb', line 8

def database
  @database
end

#idObject

The raw attributes of ref.



8
9
10
# File 'lib/fauna/objects.rb', line 8

def id
  @id
end

Instance Method Details

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

Returns true if other is a Ref and contains the same value.



43
44
45
46
# File 'lib/fauna/objects.rb', line 43

def ==(other)
  return false unless other.is_a? Ref
  id == other.id && class_ == other.class_ && database == other.database
end

#to_hashObject

Converts the Ref in Hash form.



35
36
37
38
39
40
# File 'lib/fauna/objects.rb', line 35

def to_hash
  ref = { id: id }
  ref[:class] = class_ unless class_.nil?
  ref[:database] = database unless database.nil?
  { :@ref => ref }
end

#to_sObject

Converts the Ref to a string



28
29
30
31
32
# File 'lib/fauna/objects.rb', line 28

def to_s
  cls = class_.nil? ? '' : ",class=#{class_.to_s}"
  db = database.nil? ? '' : ",database=#{database.to_s}"
  "Ref(id=#{id}#{cls}#{db})"
end