lib/mihari/structs/rule.rb in mihari-4.7.0 vs lib/mihari/structs/rule.rb in mihari-4.7.1
- old
+ new
@@ -167,21 +167,26 @@
#
# @return [Mihari::Structs::Rule::Rule]
#
def from_model(model)
data = model.data.deep_symbolize_keys
+ # set ID if YAML data do not have ID
data[:id] = model.id unless data.key?(:id)
Structs::Rule::Rule.new(data, model.yaml)
end
#
# @param [String] yaml
#
# @return [Mihari::Structs::Rule::Rule]
+ # @param [String, nil] id
#
- def from_yaml(yaml)
+ def from_yaml(yaml, id: nil)
data = load_erb_yaml(yaml)
+ # set ID if id is given & YAML data do not have ID
+ data[:id] = id if !id.nil? && !data.key?(:id)
+
Structs::Rule::Rule.new(data, yaml)
end
end
end
end