Class: SurrealDB::RecordID
- Inherits:
-
Object
- Object
- SurrealDB::RecordID
- Defined in:
- lib/surrealdb/models/record_id.rb
Overview
Represents a SurrealDB record identifier (table + id).
A RecordID uniquely identifies a record within a table. The id component can be a string, integer, array, or object.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Record identifier (String, Integer, Array, Hash).
-
#table ⇒ String
readonly
Table name.
Class Method Summary collapse
-
.parse(str) ⇒ RecordID
Parses a "table:id" string into a RecordID.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(table, id) ⇒ RecordID
constructor
A new instance of RecordID.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(table, id) ⇒ RecordID
Returns a new instance of RecordID.
17 18 19 20 21 22 |
# File 'lib/surrealdb/models/record_id.rb', line 17 def initialize(table, id) raise ArgumentError, 'table must be a non-empty string' if table.nil? || table.to_s.empty? @table = table.to_s.freeze @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns record identifier (String, Integer, Array, Hash).
13 14 15 |
# File 'lib/surrealdb/models/record_id.rb', line 13 def id @id end |
#table ⇒ String (readonly)
Returns table name.
10 11 12 |
# File 'lib/surrealdb/models/record_id.rb', line 10 def table @table end |
Class Method Details
.parse(str) ⇒ RecordID
Parses a "table:id" string into a RecordID.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/surrealdb/models/record_id.rb', line 29 def self.parse(str) parts = str.to_s.split(':', 2) raise ArgumentError, "invalid record ID: #{str}" if parts.length < 2 || parts[0].empty? table = parts[0] raw_id = parts[1] # Unwrap angle bracket escaping: ⟨...⟩ raw_id = raw_id[1..-2] if raw_id.start_with?("\u27E8") && raw_id.end_with?("\u27E9") id = try_numeric(raw_id) new(table, id) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
52 53 54 |
# File 'lib/surrealdb/models/record_id.rb', line 52 def ==(other) other.is_a?(RecordID) && other.table == @table && other.id == @id end |
#hash ⇒ Object
57 58 59 |
# File 'lib/surrealdb/models/record_id.rb', line 57 def hash [self.class, @table, @id].hash end |
#inspect ⇒ Object
48 49 50 |
# File 'lib/surrealdb/models/record_id.rb', line 48 def inspect "SurrealDB::RecordID(#{self})" end |
#to_s ⇒ Object
43 44 45 46 |
# File 'lib/surrealdb/models/record_id.rb', line 43 def to_s id_str = format_id(@id) "#{@table}:#{id_str}" end |