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.



454
455
456
# File 'lib/smplkit/management/client.rb', line 454

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

Instance Method Details

#_create_config(config) ⇒ Object



486
487
488
489
# File 'lib/smplkit/management/client.rb', line 486

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



491
492
493
494
# File 'lib/smplkit/management/client.rb', line 491

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



471
472
473
474
# File 'lib/smplkit/management/client.rb', line 471

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.

Walks every page of list_configs so an account with more than RUNTIME_PAGE_SIZE configs still resolves chains correctly.



502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
# File 'lib/smplkit/management/client.rb', line 502

def fetch_chain(target_key)
  all_configs = fetch_all_configs
  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



466
467
468
469
# File 'lib/smplkit/management/client.rb', line 466

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

#list(page_number: nil, page_size: nil) ⇒ Object



458
459
460
461
462
463
464
# File 'lib/smplkit/management/client.rb', line 458

def list(page_number: nil, page_size: nil)
  opts = {}
  opts[:page_number] = page_number unless page_number.nil?
  opts[:page_size] = page_size unless page_size.nil?
  response = ErrorMapping.call { @api.list_configs(opts) }
  (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



476
477
478
479
480
481
482
483
484
# File 'lib/smplkit/management/client.rb', line 476

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