Class: KubeSchema::Instance
- Inherits:
-
Object
- Object
- KubeSchema::Instance
- Defined in:
- lib/kube_schema/instance.rb
Overview
Represents a single Kubernetes version’s OpenAPI schema. Lazily loads the JSON and builds an index of group/version/kind strings mapped back to definition keys.
instance = KubeSchema::Instance.new("v1.33.6")
instance["Deployment"]
instance["apps/v1/Deployment"]
instance.list_resources #=> sorted array of "group/version/kind" strings
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Look up a resource by full “group/version/kind” or by bare “Kind”.
-
#initialize(version) ⇒ Instance
constructor
A new instance of Instance.
Constructor Details
#initialize(version) ⇒ Instance
Returns a new instance of Instance.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kube_schema/instance.rb', line 18 def initialize(version) @resource_classes = {} is_a_version = -> (v) { Gem::Version.correct?(v) } if is_a_version.(version) @version = version else raise UnknownVersionError.new( "\n#{version} is an unknown version..." + "\nUse `KubeSchema.schema_versions` to get a list." ) end end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
16 17 18 |
# File 'lib/kube_schema/instance.rb', line 16 def version @version end |
Instance Method Details
#[](key) ⇒ Object
Look up a resource by full “group/version/kind” or by bare “Kind”. Returns a class that inherits from KubeSchema::Resource, or nil.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/kube_schema/instance.rb', line 35 def [](key) KubeSchema::SchemaIndex.new(version).find(key.downcase).then do |path| if path.nil? raise "No resource schema found for #{key}!!!!!!!" else @resource_classes[key] ||= begin #schema_hash = @data["definitions"][key] Class.new(::KubeSchema::Resource) do #@schema = schema_hash #def self.schema # @schema || superclass.schema #end end end end end end |