Signed-off-by: Zhang Yu 2134782174@qq.com --- src/lib/job.cr | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/lib/job.cr b/src/lib/job.cr index a4345e0..c877a43 100644 --- a/src/lib/job.cr +++ b/src/lib/job.cr @@ -136,6 +136,19 @@ class Job update(json.as_h) end
+ def delete(key : String) + initialized_keys = get_initialized_keys + if initialized_keys.includes?(key) + raise "Should not delete #{key}" + else + if @hash.has_key?(key) + @hash.delete(key) + else + raise "This field does not exist: #{key}" + end + end + end + private def set_defaults append_init_field() set_user_lkp_src() @@ -324,7 +337,7 @@ class Job @hash.delete("my_uuid") end
- private def initialized? + private def get_initialized_keys() initialized_keys = [] of String
REQUIRED_KEYS.each do |key| @@ -350,7 +363,10 @@ class Job "kernel_uri", "kernel_params", "linux_vmlinuz_path"] - + end + + private def initialized? + initialized_keys = get_initialized_keys initialized_keys.each do |key| return false unless @hash.has_key?(key) end