Module: Kube::Schema
- Defined in:
- lib/kube/schema.rb,
lib/kube/schema/version.rb,
lib/kube/schema/instance.rb,
lib/kube/schema/resource.rb,
lib/kube/schema/schema_cache.rb,
lib/kube/schema/schema_index.rb
Defined Under Namespace
Modules: SchemaCache Classes: IncorrectVersionFormat, Instance, Resource, SchemaIndex, UnknownVersionError
Constant Summary collapse
- GEM_ROOT =
File.("../..", __dir__).freeze
- SCHEMA_INDEX =
File.join(GEM_ROOT, "data").freeze
- DEFAULT_VERSION =
2025-04-16
"1.34.4"- VERSION =
"1.1.0"
Class Attribute Summary collapse
-
.schema_version ⇒ Object
Set a default Kubernetes version for bare lookups like Kube::Schema.
Class Method Summary collapse
-
.[](key) ⇒ Object
Kube::Schema => cached Instance (supports [“Deployment”] chaining) Kube::Schema => Resource via the default version Kube::Schema => Resource via the default version.
- .has_version?(version) ⇒ Boolean
-
.latest_version ⇒ Object
The latest Kubernetes version available in the schemas directory, determined by sorting the filenames with Gem::Version.
-
.parse(hash) ⇒ Object
Build a Resource from a hash.
- .schema_versions ⇒ Object
Class Attribute Details
.schema_version ⇒ Object
Set a default Kubernetes version for bare lookups like Kube::Schema. When nil, the latest version found in the schemas directory is used.
24 25 26 |
# File 'lib/kube/schema.rb', line 24 def schema_version @schema_version end |
Class Method Details
.[](key) ⇒ Object
Kube::Schema => cached Instance (supports [“Deployment”] chaining) Kube::Schema => Resource via the default version Kube::Schema => Resource via the default version
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kube/schema.rb', line 29 def [](key) is_a_version = -> (key) { Gem::Version.correct?(key) } if key.start_with?("v") && Gem::Version.correct?(key.sub("v", "")) raise IncorrectVersionFormat, "\nDon't preface the version with a \"v\"." \ "\nUse Kube::Schema[\"#{key.sub("v", "")}\"] instead." end if is_a_version.(key) if has_version?(key) @instances[key] ||= Instance.new(key) else raise UnknownVersionError.new( "\n#{key} is an unknown version..." + "\nUse `Kube::Schema.schema_versions` to get a list." ) end else Instance.new(schema_version || DEFAULT_VERSION)[key] end end |
.has_version?(version) ⇒ Boolean
71 72 73 |
# File 'lib/kube/schema.rb', line 71 def has_version?(version) schema_versions.include?(version) end |
.latest_version ⇒ Object
The latest Kubernetes version available in the schemas directory, determined by sorting the filenames with Gem::Version.
67 68 69 |
# File 'lib/kube/schema.rb', line 67 def latest_version schema_versions.last end |
.parse(hash) ⇒ Object
54 55 56 |
# File 'lib/kube/schema.rb', line 54 def parse(hash) raise NotImplementedError end |
.schema_versions ⇒ Object
58 59 60 61 62 63 |
# File 'lib/kube/schema.rb', line 58 def schema_versions @schema_versions ||= Dir.glob(SCHEMA_INDEX + "/v*.txt").map do |file_path| file_path.split("/").last.gsub(".txt", "")[1..-1] end.sort_by { Gem::Version.new(_1) } end |