Class: K8y::Client::ResourceDescription
- Inherits:
-
Object
- Object
- K8y::Client::ResourceDescription
- Defined in:
- lib/k8y/client/resource_description.rb
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#name ⇒ Object
(also: #plural_name)
readonly
Returns the value of attribute name.
-
#namespaced ⇒ Object
readonly
Returns the value of attribute namespaced.
-
#verbs ⇒ Object
readonly
Returns the value of attribute verbs.
Class Method Summary collapse
Instance Method Summary collapse
- #has_verb?(verb) ⇒ Boolean
-
#initialize(name:, kind:, singular_name:, namespaced:, verbs:) ⇒ ResourceDescription
constructor
A new instance of ResourceDescription.
- #path_for_resource(namespace: nil, name:) ⇒ Object
- #path_for_resources(namespace: nil) ⇒ Object
- #singular_name ⇒ Object
- #subresource? ⇒ Boolean
Constructor Details
#initialize(name:, kind:, singular_name:, namespaced:, verbs:) ⇒ ResourceDescription
Returns a new instance of ResourceDescription.
19 20 21 22 23 24 25 |
# File 'lib/k8y/client/resource_description.rb', line 19 def initialize(name:, kind:, singular_name:, namespaced:, verbs:) @name = name @kind = kind @singular_name = singular_name @namespaced = namespaced @verbs = verbs end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
6 7 8 |
# File 'lib/k8y/client/resource_description.rb', line 6 def kind @kind end |
#name ⇒ Object (readonly) Also known as: plural_name
Returns the value of attribute name.
6 7 8 |
# File 'lib/k8y/client/resource_description.rb', line 6 def name @name end |
#namespaced ⇒ Object (readonly)
Returns the value of attribute namespaced.
6 7 8 |
# File 'lib/k8y/client/resource_description.rb', line 6 def namespaced @namespaced end |
#verbs ⇒ Object (readonly)
Returns the value of attribute verbs.
6 7 8 |
# File 'lib/k8y/client/resource_description.rb', line 6 def verbs @verbs end |
Class Method Details
.from_hash(hash) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/k8y/client/resource_description.rb', line 9 def self.from_hash(hash) new( name: hash.fetch("name"), kind: hash.fetch("kind"), singular_name: hash.fetch("singularName"), namespaced: hash.fetch("namespaced"), verbs: hash.fetch("verbs").map(&:to_sym), ) end |
Instance Method Details
#has_verb?(verb) ⇒ Boolean
39 40 41 |
# File 'lib/k8y/client/resource_description.rb', line 39 def has_verb?(verb) verbs.include?(verb) end |
#path_for_resource(namespace: nil, name:) ⇒ Object
51 52 53 |
# File 'lib/k8y/client/resource_description.rb', line 51 def path_for_resource(namespace: nil, name:) "#{path_for_resources(namespace: namespace)}/#{name}" end |
#path_for_resources(namespace: nil) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/k8y/client/resource_description.rb', line 43 def path_for_resources(namespace: nil) if namespace "namespaces/#{namespace}/#{plural_name}" else plural_name end end |
#singular_name ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/k8y/client/resource_description.rb', line 27 def singular_name if @singular_name.empty? kind.downcase else @singular_name end end |
#subresource? ⇒ Boolean
35 36 37 |
# File 'lib/k8y/client/resource_description.rb', line 35 def subresource? name.include?("/") # E.g. namespaces/status, deployments/scale, etc. end |