Class: Smplkit::ManagementClient::ConfigNamespace
- Inherits:
-
Object
- Object
- Smplkit::ManagementClient::ConfigNamespace
- Includes:
- HttpHelpers
- Defined in:
- lib/smplkit/management/client.rb
Instance Method Summary collapse
- #_create_config(config) ⇒ Object
- #_update_config(config) ⇒ Object
- #delete(key) ⇒ Object
-
#fetch_chain(target_key) ⇒ Object
Build the parent-chain for a given config, walking
parent_idpointers across the full config list. - #get(key) ⇒ Object
-
#initialize(http) ⇒ ConfigNamespace
constructor
A new instance of ConfigNamespace.
- #list ⇒ Object
- #new_config(key, name: nil, description: nil, parent: nil) ⇒ Object
Constructor Details
#initialize(http) ⇒ ConfigNamespace
Returns a new instance of ConfigNamespace.
383 384 385 |
# File 'lib/smplkit/management/client.rb', line 383 def initialize(http) @http = http end |
Instance Method Details
#_create_config(config) ⇒ Object
411 412 413 414 415 |
# File 'lib/smplkit/management/client.rb', line 411 def _create_config(config) body = Smplkit::Config::Helpers.build_config_request_body(config) resp = http_post("/api/v1/configs", body) Smplkit::Config::Helpers.config_from_json(self, resp["data"]) end |
#_update_config(config) ⇒ Object
417 418 419 420 421 |
# File 'lib/smplkit/management/client.rb', line 417 def _update_config(config) body = Smplkit::Config::Helpers.build_config_request_body(config) resp = http_put("/api/v1/configs/#{config.key}", body) Smplkit::Config::Helpers.config_from_json(self, resp["data"]) end |
#delete(key) ⇒ Object
397 398 399 |
# File 'lib/smplkit/management/client.rb', line 397 def delete(key) http_delete("/api/v1/configs/#{key}") 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.
Each chain entry is a Hash matching the wire shape that Smplkit::Config::Helpers.resolve_chain consumes.
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/smplkit/management/client.rb', line 429 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
392 393 394 395 |
# File 'lib/smplkit/management/client.rb', line 392 def get(key) resp = http_get("/api/v1/configs/#{key}") Smplkit::Config::Helpers.config_from_json(self, resp["data"]) end |
#list ⇒ Object
387 388 389 390 |
# File 'lib/smplkit/management/client.rb', line 387 def list list_resp = http_list("/api/v1/configs") list_resp.map { |r| Smplkit::Config::Helpers.config_from_json(self, r) } end |
#new_config(key, name: nil, description: nil, parent: nil) ⇒ Object
401 402 403 404 405 406 407 408 409 |
# File 'lib/smplkit/management/client.rb', line 401 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 |