Class: Smplkit::ManagementClient::ConfigNamespace

Inherits:
Object
  • Object
show all
Defined in:
lib/smplkit/management/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_client) ⇒ ConfigNamespace

Returns a new instance of ConfigNamespace.



410
411
412
# File 'lib/smplkit/management/client.rb', line 410

def initialize(api_client)
  @api = SmplkitGeneratedClient::Config::ConfigsApi.new(api_client)
end

Instance Method Details

#_create_config(config) ⇒ Object



439
440
441
442
# File 'lib/smplkit/management/client.rb', line 439

def _create_config(config)
  response = ErrorMapping.call { @api.create_config(config_body(config)) }
  Smplkit::Config::Helpers.config_from_json(self, ResourceShim.from_model(response.data))
end

#_update_config(config) ⇒ Object



444
445
446
447
# File 'lib/smplkit/management/client.rb', line 444

def _update_config(config)
  response = ErrorMapping.call { @api.update_config(config.key, config_body(config)) }
  Smplkit::Config::Helpers.config_from_json(self, ResourceShim.from_model(response.data))
end

#delete(key) ⇒ Object



424
425
426
427
# File 'lib/smplkit/management/client.rb', line 424

def delete(key)
  ErrorMapping.call { @api.delete_config(key) }
  true
end

#fetch_chain(target_key) ⇒ Object

Build the parent-chain for a given config, walking parent_id pointers across the full config list. Mirrors the Python SDK’s client-side resolution — there is no server /chain endpoint.



452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# File 'lib/smplkit/management/client.rb', line 452

def fetch_chain(target_key)
  all_configs = list
  by_key = all_configs.to_h { |c| [c.key, c] }
  by_id = all_configs.to_h { |c| [c.id, c] }

  current = by_key[target_key]
  return [] unless current

  chain = []
  loop do
    chain << config_to_chain_entry(current)
    parent_id = current.parent_id
    break if parent_id.nil? || parent_id == ""

    parent = by_id[parent_id]
    break unless parent

    current = parent
  end
  chain
end

#get(key) ⇒ Object



419
420
421
422
# File 'lib/smplkit/management/client.rb', line 419

def get(key)
  response = ErrorMapping.call { @api.get_config(key) }
  Smplkit::Config::Helpers.config_from_json(self, ResourceShim.from_model(response.data))
end

#listObject



414
415
416
417
# File 'lib/smplkit/management/client.rb', line 414

def list
  response = ErrorMapping.call { @api.list_configs }
  (response.data || []).map { |r| Smplkit::Config::Helpers.config_from_json(self, ResourceShim.from_model(r)) }
end

#new_config(key, name: nil, description: nil, parent: nil) ⇒ Object



429
430
431
432
433
434
435
436
437
# File 'lib/smplkit/management/client.rb', line 429

def new_config(key, name: nil, description: nil, parent: nil)
  Smplkit::Config::Config.new(
    self,
    key: key,
    name: name || Smplkit::Helpers.key_to_display_name(key),
    description: description,
    parent_id: parent.is_a?(Smplkit::Config::Config) ? parent.key : parent
  )
end