Class: Pvectl::Config::Models::Context
- Inherits:
-
Object
- Object
- Pvectl::Config::Models::Context
- Defined in:
- lib/pvectl/config/models/context.rb
Overview
Represents a context linking a cluster to a user.
Context is an immutable value object that binds together a cluster and user configuration, similar to kubectl contexts. It optionally includes a default node for operations.
Instance Attribute Summary collapse
-
#cluster_ref ⇒ String
readonly
Reference to cluster name.
-
#default_node ⇒ String?
readonly
Default node for operations.
-
#name ⇒ String
readonly
Unique name identifying this context.
-
#user_ref ⇒ String
readonly
Reference to user name.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Context
Creates a Context from a kubeconfig-style hash structure.
Instance Method Summary collapse
-
#initialize(name:, cluster_ref:, user_ref:, default_node: nil) ⇒ Context
constructor
Creates a new Context instance.
-
#to_hash ⇒ Hash
Converts the context to a kubeconfig-style hash structure.
Constructor Details
#initialize(name:, cluster_ref:, user_ref:, default_node: nil) ⇒ Context
Creates a new Context instance.
50 51 52 53 54 55 |
# File 'lib/pvectl/config/models/context.rb', line 50 def initialize(name:, cluster_ref:, user_ref:, default_node: nil) @name = name @cluster_ref = cluster_ref @user_ref = user_ref @default_node = default_node end |
Instance Attribute Details
#cluster_ref ⇒ String (readonly)
Returns reference to cluster name.
36 37 38 |
# File 'lib/pvectl/config/models/context.rb', line 36 def cluster_ref @cluster_ref end |
#default_node ⇒ String? (readonly)
Returns default node for operations.
42 43 44 |
# File 'lib/pvectl/config/models/context.rb', line 42 def default_node @default_node end |
#name ⇒ String (readonly)
Returns unique name identifying this context.
33 34 35 |
# File 'lib/pvectl/config/models/context.rb', line 33 def name @name end |
#user_ref ⇒ String (readonly)
Returns reference to user name.
39 40 41 |
# File 'lib/pvectl/config/models/context.rb', line 39 def user_ref @user_ref end |
Class Method Details
.from_hash(hash) ⇒ Context
Creates a Context from a kubeconfig-style hash structure.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pvectl/config/models/context.rb', line 71 def self.from_hash(hash) context_data = hash["context"] || {} new( name: hash["name"], cluster_ref: context_data["cluster"], user_ref: context_data["user"], default_node: context_data["default-node"] ) end |
Instance Method Details
#to_hash ⇒ Hash
Converts the context to a kubeconfig-style hash structure.
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/pvectl/config/models/context.rb', line 85 def to_hash context_data = { "cluster" => cluster_ref, "user" => user_ref } context_data["default-node"] = default_node if default_node { "name" => name, "context" => context_data } end |