lib/stepmod/utils/change.rb in stepmod-utils-0.4.13 vs lib/stepmod/utils/change.rb in stepmod-utils-0.4.14
- old
+ new
@@ -11,10 +11,12 @@
MODULE_TYPES = {
arm: "arm",
mim: "mim",
arm_longform: "arm_lf",
mim_longform: "mim_lf",
+ mapping: "mapping",
+ changes: "",
}.freeze
def initialize(stepmod_dir:, schema_name:, type:)
@stepmod_dir = stepmod_dir
@change_editions = Stepmod::Utils::ChangeEditionCollection.new
@@ -38,17 +40,24 @@
@change_editions[version]
end
alias_method :[], :fetch_change_edition
def save_to_file
- File.write(filepath(@type), Psych.dump(to_h))
+ change_hash = to_h
+ return if change_hash.empty?
+
+ File.write(filepath(@type), Psych.dump(change_hash))
end
def to_h
+ change_editions_list = change_editions.to_h
+
+ return {} if change_editions_list.empty?
+
{
"schema" => schema_name,
- "change_edition" => change_editions.to_h,
+ "change_edition" => change_editions_list,
}
end
private
@@ -56,11 +65,17 @@
File.join(
@stepmod_dir,
"data",
base_folder,
schema_name,
- "#{MODULE_TYPES[type.to_sym] || schema_name}.changes.yaml",
+ filename(type),
)
+ end
+
+ def filename(type)
+ return "changes.yaml" if type.to_s == "changes"
+
+ "#{MODULE_TYPES[type.to_sym] || schema_name}.changes.yaml"
end
def base_folder
if resource?
"resources"