Class: Alexandria::Preferences
- Inherits:
-
Object
- Object
- Alexandria::Preferences
- Includes:
- Logging, Singleton
- Defined in:
- lib/alexandria/preferences.rb,
lib/alexandria/default_preferences.rb
Constant Summary collapse
- 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'
- DEFAULT_VALUES =
{ "position" => [0, 0], "size" => [640, 480], "maximized" => false, "sidepane_position" => 140, "view_as" => 0, "arrange_icons_mode" => 0, "reverse_icons" => false, "barcode_scanner" => "CueCat", "play_scanning_sound" => true, "play_scan_sound" => true, "toolbar_visible" => true, "sidepane_visible" => true, "statusbar_visible" => true, "col_authors_visible" => true, "col_edition_visible" => true, "col_isbn_visible" => true, "col_publisher_visible" => true, "col_publish_date_visible" => true, "col_rating_visible" => true, "col_redd_visible" => true, "col_own_visible" => true, "col_want_visible" => true, "cols_width" => "{}", "providers_priority" => ["Amazon", "BarnesAndNoble", "AdLibris", "DeaStore", "Proxis", "Thalia", "Siciliano", "WorldCat", "MCU", "LOC", "BL", "SBN"], "view_advanced_settings" => false }
Instance Method Summary collapse
- #http_proxy_config ⇒ Object
-
#initialize ⇒ Preferences
constructor
A new instance of Preferences.
- #method_missing(id, *args) ⇒ Object
- #remove_preference(variable_name) ⇒ Object
- #save! ⇒ Object
Methods included from Logging
Constructor Details
#initialize ⇒ Preferences
Returns a new instance of Preferences.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/alexandria/preferences.rb', line 38 def initialize @alexandria_settings = {} @changed_settings = Set.new @url_handlers_loaded = false @http_command = nil @mailto_command = nil @http_proxy_loaded = false @use_http_proxy = false @proxy_host = nil @proxy_port = nil @proxy_user = nil @proxy_password = nil load_alexandria_settings end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/alexandria/preferences.rb', line 72 def method_missing(id, *args) method = id.id2name if (match = /(.*)=$/.match(method)) if args.length != 1 raise "Set method #{method} should be called with " \ "only one argument (was called with #{args.length})" end variable_name = match[1] new_value = args.first generic_setter(variable_name, new_value) else unless args.empty? raise "Get method #{method} should be called " \ "without argument (was called with #{args.length})" end generic_getter(method) end end |
Instance Method Details
#http_proxy_config ⇒ Object
56 57 58 59 60 61 |
# File 'lib/alexandria/preferences.rb', line 56 def http_proxy_config load_http_proxy_settings unless @http_proxy_loaded if @use_http_proxy && @proxy_host && @proxy_port [@proxy_host, @proxy_port, @proxy_user, @proxy_password] end end |
#remove_preference(variable_name) ⇒ Object
91 92 93 94 |
# File 'lib/alexandria/preferences.rb', line 91 def remove_preference(variable_name) @alexandria_settings.delete(variable_name) @changed_settings << variable_name end |
#save! ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/alexandria/preferences.rb', line 63 def save! log.debug { 'preferences save!' } @changed_settings.each do |variable_name| log.debug { "saving preference #{variable_name} / #{@alexandria_settings[variable_name].class}" } generic_save_setting(variable_name, @alexandria_settings[variable_name]) end @changed_settings.clear end |