Class: AxHub::Data::DataClient

Inherits:
Object
  • Object
show all
Defined in:
lib/axhub_sdk/data/client.rb

Overview

Entry point for the ergonomic data layer; holds the per-client schema cache used by discover() (mirrors node DataClient).

Instance Method Summary collapse

Constructor Details

#initialize(client, schema_cache: nil) ⇒ DataClient

Returns a new instance of DataClient.



231
232
233
234
235
236
237
238
# File 'lib/axhub_sdk/data/client.rb', line 231

def initialize(client, schema_cache: nil)
  @client = client
  @schema_cache = case schema_cache
                  when SchemaCache then schema_cache
                  when Hash then SchemaCache.new(**schema_cache.transform_keys(&:to_sym))
                  else SchemaCache.new
                  end
end

Instance Method Details

#discover(tenant_slug, app_slug, table, fresh: nil, ttl_ms: nil) ⇒ Object



250
251
252
253
254
255
256
# File 'lib/axhub_sdk/data/client.rb', line 250

def discover(tenant_slug, app_slug, table, fresh: nil, ttl_ms: nil)
  key = Data.schema_cache_key(tenant_slug, app_slug, table)
  schema = @schema_cache.get_or_set(key, fresh: fresh, ttl_ms: ttl_ms) do
    Data.fetch_discovered_schema(@client, tenant_slug, app_slug, table, fresh: fresh, ttl_ms: ttl_ms)
  end
  DataTableClient.new(@client, tenant_slug, app_slug, schema.table, schema)
end

#invalidate_schema(tenant_slug = nil, app_slug = nil, table = nil) ⇒ Object



258
259
260
261
262
263
264
# File 'lib/axhub_sdk/data/client.rb', line 258

def invalidate_schema(tenant_slug = nil, app_slug = nil, table = nil)
  if !tenant_slug.nil? && !app_slug.nil? && !table.nil?
    @schema_cache.invalidate(Data.schema_cache_key(tenant_slug, app_slug, table))
    return
  end
  @schema_cache.invalidate
end

#scoped(tenant_slug) ⇒ Object



246
247
248
# File 'lib/axhub_sdk/data/client.rb', line 246

def scoped(tenant_slug)
  TenantDataFactory.new(self, tenant_slug)
end

#table(tenant_slug, app_slug, table) ⇒ Object



240
241
242
243
244
# File 'lib/axhub_sdk/data/client.rb', line 240

def table(tenant_slug, app_slug, table)
  schema = table.is_a?(DataTableSchema) ? table : nil
  table_name = table.is_a?(DataTableSchema) ? table.table : table
  DataTableClient.new(@client, tenant_slug, app_slug, table_name, schema)
end