lib/config_base.rb in machinery-tool-1.16.2 vs lib/config_base.rb in machinery-tool-1.16.3
- old
+ new
@@ -30,10 +30,11 @@
end
abstract_method :default_config_files
abstract_method :define_entries
+ abstract_method :deprecated_entries
def entry(key, parameters = {})
key = normalize_key(key)
@entries[key] = { value: parameters[:default], description: parameters[:description] }
@@ -51,22 +52,27 @@
ensure_config_exists(key)
@entries[key][:value]
end
def set(key, value, options = {auto_save: true} )
- key = normalize_key(key)
- ensure_config_exists(key)
+ if deprecated?(key)
+ @entries.delete(key)
+ else
+ key = normalize_key(key)
+ ensure_config_exists(key)
- # Check if data type is correct. true and false are not of the same type which makes the check complex
- if value.class != @entries[key][:value].class &&
- !(boolean?(value) && boolean?(@entries[key][:value]))
- raise Machinery::Errors::MachineryError,
- "The value '#{value}' for configuration key '#{key}' is of an invalid data type."
+ # Check if data type is correct. true and false are not of the same type which makes the
+ # check complex
+ if value.class != @entries[key][:value].class &&
+ !(boolean?(value) && boolean?(@entries[key][:value]))
+ raise Machinery::Errors::MachineryError,
+ "The value '#{value}' for configuration key '#{key}' is of an invalid data type."
+ end
+
+ @entries[key][:value] = value
end
- @entries[key][:value] = value
-
save if options[:auto_save]
end
private
@@ -75,11 +81,11 @@
end
def save
config_table_stripped = {}
@entries.each do |key,value|
- config_table_stripped[key] = value[:value]
+ config_table_stripped[key] = value[:value] unless deprecated?(key)
end
FileUtils.mkdir_p(File.dirname(file))
begin
@@ -92,10 +98,12 @@
def apply_custom_config(file)
content = read_config_file(file) || []
content.each do |key, value|
+ next if deprecated?(key)
+
begin
set(key, value, :auto_save => false )
rescue => e
Machinery::Ui.warn "Warning: The machinery config file '#{file}' contains an invalid entry '#{key}':\n#{e}"
end
@@ -126,7 +134,11 @@
key.gsub("-", "_")
end
def unnormalize_key(key)
key.gsub("_", "-")
+ end
+
+ def deprecated?(key)
+ deprecated_entries.include?(key)
end
end