Class: K8s::Resource
- Inherits:
-
RecursiveOpenStruct
- Object
- RecursiveOpenStruct
- K8s::Resource
- Extended by:
- Forwardable
- Includes:
- Comparable
- Defined in:
- lib/k8s/resource.rb
Overview
generic untyped resource
Class Method Summary collapse
- .from_file(filename) ⇒ K8s::Resource
- .from_files(path) ⇒ Array<K8s::Resource>
- .from_json(data) ⇒ self
Instance Method Summary collapse
- #<=>(other) ⇒ Boolean
-
#initialize(hash, recurse_over_arrays: true, **options) ⇒ Resource
constructor
A new instance of Resource.
-
#merge(attrs) ⇒ K8s::Resource
merge in fields.
- #to_json(**options) ⇒ String
Constructor Details
#initialize(hash, recurse_over_arrays: true, **options) ⇒ Resource
Returns a new instance of Resource.
35 36 37 38 39 40 |
# File 'lib/k8s/resource.rb', line 35 def initialize(hash, recurse_over_arrays: true, **) super(hash, recurse_over_arrays: recurse_over_arrays, ** ) end |
Class Method Details
.from_file(filename) ⇒ K8s::Resource
18 19 20 |
# File 'lib/k8s/resource.rb', line 18 def self.from_file(filename) new(YAML.load_file(filename)) end |
.from_files(path) ⇒ Array<K8s::Resource>
24 25 26 27 28 29 30 31 32 |
# File 'lib/k8s/resource.rb', line 24 def self.from_files(path) stat = File.stat(path) if stat.directory? Dir.glob("#{path}/*.{yml,yaml}").map{|path| self.load_files(path) }.flatten else ::YAML.load_stream(File.read(path), path).map{|doc| new(doc) } end end |
.from_json(data) ⇒ self
12 13 14 |
# File 'lib/k8s/resource.rb', line 12 def self.from_json(data) return new(data) end |
Instance Method Details
#<=>(other) ⇒ Boolean
49 50 51 |
# File 'lib/k8s/resource.rb', line 49 def <=>(other) to_hash <=> other.to_hash end |
#merge(attrs) ⇒ K8s::Resource
merge in fields
57 58 59 60 61 62 63 64 65 |
# File 'lib/k8s/resource.rb', line 57 def merge(attrs) # deep clone of attrs h = to_hash # merge in-place h.deep_merge!(attrs.to_hash, overwrite_arrays: true) self.class.new(h) end |
#to_json(**options) ⇒ String
43 44 45 |
# File 'lib/k8s/resource.rb', line 43 def to_json(**) to_hash.to_json(**) end |