Class: Cloudflare::DurableObjectId

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudflare_workers/durable_object.rb

Overview

Wraps a JS DurableObjectId (opaque token returned by ‘namespace.idFromName(…)` / `namespace.newUniqueId()`). Carries the raw JS id so we can round-trip it into `namespace.get(id)`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(js_id) ⇒ DurableObjectId

Returns a new instance of DurableObjectId.



62
63
64
# File 'lib/cloudflare_workers/durable_object.rb', line 62

def initialize(js_id)
  @js_id = js_id
end

Instance Attribute Details

#js_idObject (readonly)

Returns the value of attribute js_id.



60
61
62
# File 'lib/cloudflare_workers/durable_object.rb', line 60

def js_id
  @js_id
end

Instance Method Details

#to_sObject

Hex string representation (stable across invocations for a named id).



67
68
69
70
# File 'lib/cloudflare_workers/durable_object.rb', line 67

def to_s
  js = @js_id
  `(#{js} && typeof #{js}.toString === 'function' ? #{js}.toString() : String(#{js} || ''))`
end