lib/alexandria/preferences.rb in alexandria-book-collection-manager-0.7.1 vs lib/alexandria/preferences.rb in alexandria-book-collection-manager-0.7.2
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
# Copyright (C) 2004-2006 Laurent Sansonetti
# Copyright (C) 2011 Cathal Mc Ginley
# Copyright (C) 2011, 2016 Matijs van Zuijlen
#
# Alexandria is free software; you can redistribute it and/or
@@ -24,16 +26,16 @@
module Alexandria
class Preferences
include Singleton
include Logging
- APP_DIR = '/apps/alexandria'.freeze
- HTTP_PROXY_DIR = '/system/http_proxy'.freeze
- HTTP_PROXY_MODE = '/system/proxy/mode'.freeze
- URL_HANDLERS_DIR = '/desktop/gnome/url-handlers'.freeze
+ APP_DIR = '/apps/alexandria'
+ HTTP_PROXY_DIR = '/system/http_proxy'
+ HTTP_PROXY_MODE = '/system/proxy/mode'
+ URL_HANDLERS_DIR = '/desktop/gnome/url-handlers'
- GCONFTOOL = 'gconftool-2'.freeze
+ GCONFTOOL = 'gconftool-2'
def initialize
@alexandria_settings = {}
@changed_settings = Set.new
@@ -114,13 +116,11 @@
# when setting array, first remove nil elements (fixing #9007)
new_value.compact!
end
old_value = @alexandria_settings[variable_name]
@alexandria_settings[variable_name] = new_value
- unless new_value == old_value
- @changed_settings << variable_name
- end
+ @changed_settings << variable_name unless new_value == old_value
end
def generic_save_setting(variable_name, new_value)
var_path = APP_DIR + '/' + variable_name
if new_value.is_a?(Array)
@@ -178,13 +178,11 @@
`gconftool-2 --type list --list-type #{list_type} --set #{var_path} "#{list}"`
end
end
def make_list_string(list)
- if get_gconf_type(list.first) == 'string'
- list.map! { |x| x.gsub(/\"/, '\\"') }
- end
+ list.map! { |x| x.gsub(/\"/, '\\"') } if get_gconf_type(list.first) == 'string'
contents = list.join(',')
'[' + contents + ']'
end
def exec_gconf_set(var_path, new_value)
@@ -243,12 +241,10 @@
# #discriminate method) and returns them in a Hash.
def gconftool_values_to_hash(all_vals)
hash = {}
vals = all_vals.split(/$/)
vals.each do |val|
- if /([a-z_]+) = (.*)/ =~ val
- hash[Regexp.last_match[1]] = discriminate(Regexp.last_match[2])
- end
+ hash[Regexp.last_match[1]] = discriminate(Regexp.last_match[2]) if /([a-z_]+) = (.*)/ =~ val
end
hash
end
# Make a judgement about the type of the settings we get back from