Skip to content

Commit

Permalink
moved value check to sysctl class
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Feb 7, 2020
1 parent 9a42aa5 commit 5074004
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
28 changes: 14 additions & 14 deletions library/general/src/lib/cfa/sysctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,24 @@ def present?(attr)
!send(method_name(attr)).nil?
end

# Returning value if the attribute is available
# Returns the list of attributes with a value
#
# @param attr [String] Attribute name
# @return [String] Attribute value; nil if the attribute has not found
def attr_value(attr)
send(method_name(attr))
# @return [Array<Symbol>] List of attribute names
# @see #present?
def present_attributes
self.class.known_attributes.select { |a| present?(a) }
end

# Returning hash of attributes together with there values.
# Determines the list of conflicting attributes for two files
#
# @return [Hash<String,String>] Hash of attribute values
def present_attributes
attributes = {}
ATTRIBUTES.keys.uniq.each do |k|
value = attr_value(k)
attributes[k] = value if value
end
attributes
# Two attributes are conflicting when both of them are defined with
# different values.
#
# @param other [BaseModel] The file to compare with
# @return [Array<Symbol>] List of conflicting attributes
def conflicts(other)
conflicting_attrs = present_attributes & other.present_attributes
conflicting_attrs.reject { |a| public_send(a) == other.public_send(a) }
end

private
Expand Down
4 changes: 2 additions & 2 deletions library/general/src/lib/cfa/sysctl_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def conflict_files(only: [])
higher_precedence_files.each do |file|
# Checking all "higher" files if their values overrule the current
# YAST settings.
higher_attr = file.present_attributes
file_list << file.file_path if conflicting_attrs.any? { |k, v| !higher_attr[k].nil? && v != higher_attr[k] }
conflicts = yast_config_file.conflicts(file) & conflicting_attrs
file_list << file.file_path unless conflicts.empty?
end
file_list
end
Expand Down

0 comments on commit 5074004

Please sign in to comment.