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_loaned_to_visible" => true, "col_rating_visible" => true, "col_redd_visible" => true, "col_own_visible" => true, "col_want_visible" => true, "col_tags_visible" => true, "cols_width" => "{}", "providers_priority" => ["Amazon", "BarnesAndNoble", "AdLibris", "Proxis", "Thalia", "Siciliano", "WorldCat", "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.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/alexandria/preferences.rb', line 23 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
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/alexandria/preferences.rb', line 60 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
41 42 43 44 45 46 |
# File 'lib/alexandria/preferences.rb', line 41 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
79 80 81 82 |
# File 'lib/alexandria/preferences.rb', line 79 def remove_preference(variable_name) @alexandria_settings.delete(variable_name) @changed_settings << variable_name end |
#save! ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/alexandria/preferences.rb', line 48 def save! log.debug { "preferences save!" } @changed_settings.each do |variable_name| log.debug do klass = @alexandria_settings[variable_name].class "saving preference #{variable_name} / #{klass}" end generic_save_setting(variable_name, @alexandria_settings[variable_name]) end @changed_settings.clear end |