Class: Supabase::ClientOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/supabase/client_options.rb

Overview

Structured options passed to create_client / Client. Mirrors supabase-py’s ‘SyncClientOptions` / `AsyncClientOptions`. The Ruby port uses one class because the sync/async split is decided at runtime via the `async:` flag on the umbrella client.

opts = Supabase::ClientOptions.new(
  schema: "public",
  headers: { "X-Tenant" => "acme" },
  auto_refresh_token: true,
  persist_session: true,
  postgrest_client_timeout: 30,
  storage_client_timeout: 20,
  function_client_timeout: 10,
  flow_type: "pkce"
)

Supabase.create_client(supabase_url: url, supabase_key: key, options: opts)

Constant Summary collapse

DEFAULT_POSTGREST_TIMEOUT =
120
DEFAULT_STORAGE_TIMEOUT =
20
DEFAULT_FUNCTIONS_TIMEOUT =
60
DEFAULT_HEADERS =
{ "X-Client-Info" => "supabase-rb/#{Supabase::VERSION}" }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema: "public", headers: nil, auto_refresh_token: true, persist_session: true, realtime: nil, postgrest_client_timeout: DEFAULT_POSTGREST_TIMEOUT, storage_client_timeout: DEFAULT_STORAGE_TIMEOUT, function_client_timeout: DEFAULT_FUNCTIONS_TIMEOUT, flow_type: "pkce", storage: nil, http_client: nil) ⇒ ClientOptions

Returns a new instance of ClientOptions.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/supabase/client_options.rb', line 34

def initialize(schema: "public",
               headers: nil,
               auto_refresh_token: true,
               persist_session: true,
               realtime: nil,
               postgrest_client_timeout: DEFAULT_POSTGREST_TIMEOUT,
               storage_client_timeout: DEFAULT_STORAGE_TIMEOUT,
               function_client_timeout: DEFAULT_FUNCTIONS_TIMEOUT,
               flow_type: "pkce",
               storage: nil,
               http_client: nil)
  @schema                   = schema
  @headers                  = DEFAULT_HEADERS.merge(headers || {})
  @auto_refresh_token       = auto_refresh_token
  @persist_session          = persist_session
  @realtime                 = realtime
  @postgrest_client_timeout = postgrest_client_timeout
  @storage_client_timeout   = storage_client_timeout
  @function_client_timeout  = function_client_timeout
  @flow_type                = flow_type
  @storage                  = storage
  @http_client              = http_client
end

Instance Attribute Details

#auto_refresh_tokenObject

Returns the value of attribute auto_refresh_token.



30
31
32
# File 'lib/supabase/client_options.rb', line 30

def auto_refresh_token
  @auto_refresh_token
end

#flow_typeObject

Returns the value of attribute flow_type.



30
31
32
# File 'lib/supabase/client_options.rb', line 30

def flow_type
  @flow_type
end

#function_client_timeoutObject

Returns the value of attribute function_client_timeout.



30
31
32
# File 'lib/supabase/client_options.rb', line 30

def function_client_timeout
  @function_client_timeout
end

#headersObject

Returns the value of attribute headers.



30
31
32
# File 'lib/supabase/client_options.rb', line 30

def headers
  @headers
end

#http_clientObject

Returns the value of attribute http_client.



30
31
32
# File 'lib/supabase/client_options.rb', line 30

def http_client
  @http_client
end

#persist_sessionObject

Returns the value of attribute persist_session.



30
31
32
# File 'lib/supabase/client_options.rb', line 30

def persist_session
  @persist_session
end

#postgrest_client_timeoutObject

Returns the value of attribute postgrest_client_timeout.



30
31
32
# File 'lib/supabase/client_options.rb', line 30

def postgrest_client_timeout
  @postgrest_client_timeout
end

#realtimeObject

Returns the value of attribute realtime.



30
31
32
# File 'lib/supabase/client_options.rb', line 30

def realtime
  @realtime
end

#schemaObject

Returns the value of attribute schema.



30
31
32
# File 'lib/supabase/client_options.rb', line 30

def schema
  @schema
end

#storageObject

Returns the value of attribute storage.



30
31
32
# File 'lib/supabase/client_options.rb', line 30

def storage
  @storage
end

#storage_client_timeoutObject

Returns the value of attribute storage_client_timeout.



30
31
32
# File 'lib/supabase/client_options.rb', line 30

def storage_client_timeout
  @storage_client_timeout
end

Instance Method Details

#replace(**overrides) ⇒ Object

Returns a new ClientOptions with the given fields overridden. Mirrors supabase-py’s ‘replace()` — handy because dataclasses there are frozen at the field-level and we want the same “build then derive” ergonomics.



61
62
63
64
# File 'lib/supabase/client_options.rb', line 61

def replace(**overrides)
  attrs = to_h.merge(overrides)
  self.class.new(**attrs)
end

#to_hObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/supabase/client_options.rb', line 66

def to_h
  {
    schema:                   @schema,
    headers:                  @headers,
    auto_refresh_token:       @auto_refresh_token,
    persist_session:          @persist_session,
    realtime:                 @realtime,
    postgrest_client_timeout: @postgrest_client_timeout,
    storage_client_timeout:   @storage_client_timeout,
    function_client_timeout:  @function_client_timeout,
    flow_type:                @flow_type,
    storage:                  @storage,
    http_client:              @http_client
  }
end