Class: Fauna::Ref
- Inherits:
-
Object
- Object
- Fauna::Ref
- Defined in:
- lib/fauna/objects.rb
Overview
A Ref.
Reference: FaunaDB Special Types
Instance Attribute Summary collapse
-
#class_ ⇒ Object
The raw attributes of ref.
-
#database ⇒ Object
The raw attributes of ref.
-
#id ⇒ Object
The raw attributes of ref.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Returns
trueifotheris a Ref and contains the same value. -
#initialize(id, class_ = nil, database = nil) ⇒ Ref
constructor
Creates a Ref object.
-
#to_hash ⇒ Object
Converts the Ref in Hash form.
-
#to_s ⇒ Object
Converts the Ref to a string.
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 |
#database ⇒ Object
The raw attributes of ref.
8 9 10 |
# File 'lib/fauna/objects.rb', line 8 def database @database end |
#id ⇒ Object
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_hash ⇒ Object
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_s ⇒ Object
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 |