Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Combine changed_preferences with changed_preferences_group and rename…

… to preferences_changed
  • Loading branch information...
commit 9bfe0eeeb7e2522b7f75b2f0186edcde89ade0e3 1 parent 4211878
@obrie obrie authored
Showing with 16 additions and 16 deletions.
  1. +16 −16 lib/preferences.rb
View
32 lib/preferences.rb
@@ -405,9 +405,9 @@ def write_preference(name, value, group = nil)
group = group.is_a?(Symbol) ? group.to_s : group
assert_valid_preference(name)
- unless changed_preferences_group(group).include?(name)
+ unless preferences_changed(group).include?(name)
old = clone_preference_value(name, group)
- changed_preferences_group(group)[name] = old if preference_value_changed?(name, old, value)
+ preferences_changed(group)[name] = old if preference_value_changed?(name, old, value)
end
preferences_group(group)[name] = value
@@ -421,7 +421,7 @@ def reload(*args)
@all_preferences_loaded = false
@preferences.clear if @preferences
- changed_preferences.clear
+ preferences_changed.clear
result
end
@@ -445,17 +445,6 @@ def preferences_group_loaded?(group)
@all_preferences_loaded || preference_definitions.length == preferences_group(group).length
end
- # Keeps track of all preferences that have been changed so that they can
- # be properly updated in the database. Maps group -> preference -> value.
- def changed_preferences
- @changed_preferences ||= {}
- end
-
- # Gets the set of changed preferences identified by the given group
- def changed_preferences_group(group)
- changed_preferences[group] ||= {}
- end
-
# Generates a clone of the current value stored for the preference with
# the given name / group
def clone_preference_value(name, group)
@@ -465,6 +454,17 @@ def clone_preference_value(name, group)
value
end
+ # Keeps track of all preferences that have been changed so that they can
+ # be properly updated in the database. Maps group -> preference -> value.
+ def preferences_changed(*args)
+ @preferences_changed ||= {}
+ if args.empty?
+ @preferences_changed
+ else
+ @preferences_changed[args.first] ||= {}
+ end
+ end
+
# Determines whether the old value is different from the new value for the
# given preference. This will use the typecasted value to determine
# equality.
@@ -484,7 +484,7 @@ def preference_value_changed?(name, old, value)
# Updates any preferences that have been changed/added since the record
# was last saved
def update_preferences
- changed_preferences.each do |group, preferences|
+ preferences_changed.each do |group, preferences|
group_id, group_type = Preference.split_group(group)
preferences.keys.each do |name|
@@ -497,7 +497,7 @@ def update_preferences
end
end
- changed_preferences.clear
+ preferences_changed.clear
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.