Class: Kube::Schema::Resource
- Inherits:
-
Object
- Object
- Kube::Schema::Resource
- Defined in:
- lib/kube/schema/resource.rb
Class Method Summary collapse
-
.schema ⇒ Object
Gets overridden by the factory in Kube::Schema::Instance.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(hash = {}, &block) ⇒ Resource
constructor
Subclasses generated by Instance#[] have a class-level .schema.
- #to_h ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(hash = {}, &block) ⇒ Resource
Subclasses generated by Instance#[] have a class-level .schema.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/kube/schema/resource.rb', line 12 def initialize(hash = {}, &block) hash = deep_stringify_keys(hash) if self.class.schema schemer = JSONSchemer.schema(self.class.schema, insert_property_defaults: true) schemer.valid?(hash) end @data = BlackHoleStruct.new(hash) @data.instance_exec(&block) if block end |
Class Method Details
.schema ⇒ Object
Gets overridden by the factory in Kube::Schema::Instance
25 26 27 |
# File 'lib/kube/schema/resource.rb', line 25 def self.schema nil end |
Instance Method Details
#==(other) ⇒ Object
40 41 42 |
# File 'lib/kube/schema/resource.rb', line 40 def ==(other) other.is_a?(Resource) && to_h == other.to_h end |
#to_h ⇒ Object
36 37 38 |
# File 'lib/kube/schema/resource.rb', line 36 def to_h @data.to_h end |
#valid? ⇒ Boolean
29 30 31 32 33 34 |
# File 'lib/kube/schema/resource.rb', line 29 def valid? return true if self.class.schema.nil? schemer = JSONSchemer.schema(self.class.schema) schemer.valid?(deep_stringify_keys(to_h)) end |