C0 code coverage information
Generated on Tue Oct 16 11:40:49 -0400 2007 with rcov 0.8.0
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 # Copyright (C) 2004-2006 Laurent Sansonetti
2 #
3 # Alexandria is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License as
5 # published by the Free Software Foundation; either version 2 of the
6 # License, or (at your option) any later version.
7 #
8 # Alexandria is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public
14 # License along with Alexandria; see the file COPYING. If not,
15 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 # Boston, MA 02111-1307, USA.
17
18 require 'singleton'
19
20 begin
21 require 'gconf2'
22 require 'alexandria/default_preferences'
23
24 module Alexandria
25 class Preferences
26 include Singleton
27
28 def initialize
29 @client = GConf::Client.default
30 end
31
32 APP_DIR = "/apps/alexandria/"
33 def method_missing(id, *args)
34 method = id.id2name
35 if match = /(.*)=$/.match(method)
36 if args.length != 1
37 raise "Set method #{method} should be called with " +
38 "only one argument (was called with #{args.length})"
39 end
40
41 variable_name = match[1]
42 new_value = args.first
43
44 if new_value.is_a?(Array) and new_value.empty?
45 remove_preference(variable_name)
46 else
47 @client[APP_DIR + variable_name] = new_value
48 end
49 else
50 unless args.empty?
51 raise "Get method #{method} should be called " +
52 "without argument (was called with #{args.length})"
53 end
54
55 value = @client[APP_DIR + method]
56 value == nil ? DEFAULT_VALUES[method] : value
57 end
58 end
59
60 def remove_preference(name)
61 @client.unset(APP_DIR + name)
62 end
63
64 URL_HANDLERS_DIR = "/desktop/gnome/url-handlers/"
65 def www_browser
66 dir = URL_HANDLERS_DIR + "http/"
67 @client[dir + "command"] if @client[dir + "enabled"]
68 end
69
70 def email_client
71 dir = URL_HANDLERS_DIR + "mailto/"
72 @client[dir + "command"] if @client[dir + "enabled"]
73 end
74
75 def http_proxy_config
76 if @client["/system/http_proxy/use_http_proxy"] and
77 @client["/system/proxy/mode"] == "manual"
78
79 host, port, user, pass = %w{host port authentication_user
80 authentication_password}.map do |x|
81
82 case y = @client["/system/http_proxy/" + x]
83 when Integer
84 y == 0 ? nil : y
85 when String
86 (y.strip.empty?) ? nil : y
87 end
88 end
89
90 [ host, port, user, pass ] if host and port
91 end
92 end
93 end
94 end
95
96 rescue LoadError
97
98 module Alexandria
99 class Preferences
100 include Singleton
101 include OSX
102
103 def initialize
104 @userDefaults = NSUserDefaults.standardUserDefaults
105 # register defaults here
106 end
107
108 def method_missing(id, *args)
109 method = id.id2name
110 if match = /(.*)=$/.match(method)
111 if args.length != 1
112 raise "Set method #{method} should be called with " +
113 "only one argument (was called with #{args.length})"
114 end
115 puts "#{match[1]} -> #{args.first}"
116 _sync { @userDefaults.setObject_forKey(args.first, match[1]) }
117 else
118 unless args.empty?
119 raise "Get method #{method} should be called " +
120 "without argument (was called with #{args.length})"
121 end
122 _convertToRubyObject(_sync { @userDefaults.objectForKey(method) })
123 end
124 end
125
126 def remove_preference(name)
127 @userDefaults.removeObjectForKey(name)
128 end
129
130 #######
131 private
132 #######
133
134 def _sync(&p)
135 if ExecutionQueue.current != nil
136 ExecutionQueue.current.sync_call(p)
137 else
138 p.call
139 end
140 end
141
142 def _convertToRubyObject(object)
143 if object.nil?
144 nil
145 elsif object.isKindOfClass?(NSString.oc_class)
146 object.to_s
147 elsif object.isKindOfClass?(NSNumber.oc_class)
148 object.intValue
149 elsif object.isKindOfClass?(NSArray.oc_class)
150 object.to_a.map { |x| _convertToRubyObject(x) }
151 else
152 nil
153 end
154 end
155 end
156 end
157 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.