plist4r 0.2.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.yardopts +11 -0
- data/LICENSE +3 -1
- data/README.rdoc +25 -122
- data/Rakefile +14 -0
- data/VERSION +1 -1
- data/bin/plist4r +2 -0
- data/ext/osx_plist/Makefile +157 -0
- data/ext/osx_plist/extconf.rb +9 -0
- data/ext/osx_plist/plist.c +606 -0
- data/ext/osx_plist/plist.o +0 -0
- data/lib/plist4r.rb +6 -3
- data/lib/plist4r/application.rb +1 -2
- data/lib/plist4r/backend.rb +102 -34
- data/lib/plist4r/backend/c_f_property_list.rb +65 -0
- data/lib/plist4r/backend/c_f_property_list/LICENSE +19 -0
- data/lib/plist4r/backend/c_f_property_list/README +34 -0
- data/lib/plist4r/backend/c_f_property_list/cfpropertylist.rb +6 -0
- data/lib/plist4r/backend/c_f_property_list/rbBinaryCFPropertyList.rb +663 -0
- data/lib/plist4r/backend/c_f_property_list/rbCFPlistError.rb +26 -0
- data/lib/plist4r/backend/c_f_property_list/rbCFPropertyList.rb +348 -0
- data/lib/plist4r/backend/c_f_property_list/rbCFTypes.rb +241 -0
- data/lib/plist4r/backend/c_f_property_list/rbXMLCFPropertyList.rb +116 -0
- data/lib/plist4r/backend/example.rb +37 -52
- data/lib/plist4r/backend/haml.rb +47 -36
- data/lib/plist4r/backend/libxml4r.rb +24 -20
- data/lib/plist4r/backend/osx_plist.rb +82 -0
- data/lib/plist4r/backend/ruby_cocoa.rb +172 -54
- data/lib/plist4r/backend/test/data_types.rb +163 -0
- data/lib/plist4r/backend/test/harness.rb +255 -0
- data/lib/plist4r/backend/test/output.rb +47 -0
- data/lib/plist4r/backend_base.rb +4 -2
- data/lib/plist4r/{options.rb → cli.rb} +2 -1
- data/lib/plist4r/commands.rb +13 -8
- data/lib/plist4r/config.rb +36 -9
- data/lib/plist4r/docs/Backends.html +59 -0
- data/lib/plist4r/docs/DeveloperGuide.rdoc +53 -0
- data/lib/plist4r/docs/EditingPlistFiles.rdoc +88 -0
- data/lib/plist4r/docs/InfoPlistExample.rdoc +33 -0
- data/lib/plist4r/docs/LaunchdPlistExample.rdoc +33 -0
- data/lib/plist4r/docs/PlistKeyNames.rdoc +47 -0
- data/lib/plist4r/mixin/array_dict.rb +61 -0
- data/lib/plist4r/mixin/data_methods.rb +178 -54
- data/lib/plist4r/mixin/haml4r.rb +4 -0
- data/lib/plist4r/mixin/haml4r/css_attributes.rb +19 -0
- data/lib/plist4r/mixin/haml4r/examples.rb +261 -0
- data/lib/plist4r/mixin/haml4r/haml_table_example.rb +79 -0
- data/lib/plist4r/mixin/haml4r/table.rb +157 -0
- data/lib/plist4r/mixin/haml4r/table_cell.rb +160 -0
- data/lib/plist4r/mixin/haml4r/table_cells.rb +485 -0
- data/lib/plist4r/mixin/haml4r/table_section.rb +101 -0
- data/lib/plist4r/mixin/ordered_hash.rb +9 -1
- data/lib/plist4r/mixin/popen4.rb +1 -1
- data/lib/plist4r/mixin/ruby_stdlib.rb +154 -1
- data/lib/plist4r/mixin/script.rb +133 -0
- data/lib/plist4r/mixin/table.rb +435 -0
- data/lib/plist4r/plist.rb +272 -94
- data/lib/plist4r/plist_cache.rb +42 -43
- data/lib/plist4r/plist_type.rb +31 -74
- data/lib/plist4r/plist_type/info.rb +157 -3
- data/lib/plist4r/plist_type/launchd.rb +54 -48
- data/lib/plist4r/plist_type/plist.rb +1 -3
- data/plist4r.gemspec +74 -14
- data/spec/{examples.rb → launchd_examples.rb} +131 -139
- data/spec/plist4r/application_spec.rb +37 -0
- data/spec/plist4r/backend_spec.rb +256 -0
- data/spec/plist4r/cli_spec.rb +25 -0
- data/spec/plist4r/commands_spec.rb +20 -0
- data/spec/plist4r/config_spec.rb +38 -0
- data/spec/plist4r/mixin/array_dict_spec.rb +120 -0
- data/spec/plist4r/mixin/data_methods_spec.rb +96 -0
- data/spec/plist4r/mixin/haml4r/examples.rb +261 -0
- data/spec/plist4r/mixin/ruby_stdlib_spec.rb +228 -0
- data/spec/plist4r/plist_cache_spec.rb +261 -0
- data/spec/plist4r/plist_spec.rb +841 -23
- data/spec/plist4r/plist_type_spec.rb +126 -0
- data/spec/plist4r_spec.rb +53 -27
- data/spec/scratchpad.rb +226 -0
- data/spec/spec_helper.rb +5 -1
- metadata +109 -23
- data/lib/plist4r/backend/plutil.rb +0 -25
- data/lib/plist4r/mixin.rb +0 -7
- data/plists/array_mini.xml +0 -14
- data/plists/example_big_binary.plist +0 -0
- data/plists/example_medium_binary_launchd.plist +0 -0
- data/plists/example_medium_launchd.xml +0 -53
- data/plists/mini.xml +0 -12
- data/test.rb +0 -40
@@ -0,0 +1,255 @@
|
|
1
|
+
|
2
|
+
require 'plist4r/backend/test/data_types'
|
3
|
+
require 'benchmark'
|
4
|
+
require 'plist4r/mixin/ruby_stdlib'
|
5
|
+
require 'plist4r/mixin/haml4r/table'
|
6
|
+
|
7
|
+
module Plist4r
|
8
|
+
|
9
|
+
class Backend
|
10
|
+
module Test
|
11
|
+
|
12
|
+
class Harness < Plist4r::Backend
|
13
|
+
def initialize *args, &blk
|
14
|
+
|
15
|
+
@backends = Dir.glob(File.dirname(__FILE__) + "/../../backend/*.rb").collect {|b| File.basename(b,".rb") }
|
16
|
+
@backends.flatten!
|
17
|
+
@backends.uniq!
|
18
|
+
@backends = @backends - ["example"]
|
19
|
+
|
20
|
+
@data_types = DataTypes.new
|
21
|
+
end
|
22
|
+
|
23
|
+
ReferenceBackends = {
|
24
|
+
:from_xml => :libxml4r,
|
25
|
+
:to_xml => :haml,
|
26
|
+
:from_binary => :c_f_property_list,
|
27
|
+
:to_binary => :c_f_property_list,
|
28
|
+
# :from_binary => :ruby_cocoa,
|
29
|
+
# :to_binary => :ruby_cocoa,
|
30
|
+
:from_binary => :osx_plist,
|
31
|
+
:to_binary => :osx_plist,
|
32
|
+
}
|
33
|
+
|
34
|
+
def reference_backend_for meth
|
35
|
+
ReferenceBackends[meth]
|
36
|
+
end
|
37
|
+
|
38
|
+
def results
|
39
|
+
@results
|
40
|
+
end
|
41
|
+
|
42
|
+
def run_tests
|
43
|
+
|
44
|
+
ref_strings = {}
|
45
|
+
ref_string_1024 = {}
|
46
|
+
|
47
|
+
cols = [:from, :to].size + [:xml, :binary].size
|
48
|
+
rows = @backends.size
|
49
|
+
|
50
|
+
t = Haml4r::Table.new :size => [0..cols-1, 0..rows-1]
|
51
|
+
|
52
|
+
t.col_header.size [0..cols-1, 0]
|
53
|
+
t.row_header.size [0, 0..rows-1]
|
54
|
+
|
55
|
+
# t.css_style = "border-spacing: 5px;"
|
56
|
+
c2 = "#F5F5FF"
|
57
|
+
c1 = "#FAFAFA"
|
58
|
+
cpv = 5
|
59
|
+
cph = 15
|
60
|
+
t.cells.css_style = "padding: #{cpv}px; padding-left: #{cph}px; padding-right: #{cph}px; background-color: #{c1}; text-align: center"
|
61
|
+
t.col_header.cells.css_style = "padding: #{cpv}px; padding-left: #{cph}px; padding-right: #{cph}px; background-color: #{c2}; text-align: center"
|
62
|
+
t.row_header.cells.css_style = "padding: #{cpv}px; padding-left: #{cph}px; padding-right: #{cph}px; background-color: #{c2}; text-align: right"
|
63
|
+
|
64
|
+
bhi = 0
|
65
|
+
@backends.each do |b_sym|
|
66
|
+
t.row_header.cell(0, bhi).content = "#{b_sym}"
|
67
|
+
bhi += 1
|
68
|
+
end
|
69
|
+
|
70
|
+
chi = 0
|
71
|
+
[:xml, :binary].each do |fmt|
|
72
|
+
[:from, :to].each do |op|
|
73
|
+
t.col_header.cell(chi, 0).content = ":#{op}_#{fmt}"
|
74
|
+
chi += 1
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
cgi = 0
|
79
|
+
[:xml, :binary].each do |fmt|
|
80
|
+
puts ""
|
81
|
+
puts fmt.inspect
|
82
|
+
puts ""
|
83
|
+
# setup reference test data
|
84
|
+
api_sym = "to_#{fmt}".to_sym
|
85
|
+
ref_strings[fmt] = Plist4r::OrderedHash.new
|
86
|
+
@data_types.plists.each_pair do |key,plist|
|
87
|
+
plist.backends [reference_backend_for(api_sym)]
|
88
|
+
ref_strings[fmt][key] = plist.send(api_sym)
|
89
|
+
end
|
90
|
+
|
91
|
+
@data_types.plist_1024.backends [reference_backend_for(api_sym)]
|
92
|
+
ref_string_1024[fmt] = @data_types.plist_1024.send(api_sym)
|
93
|
+
|
94
|
+
|
95
|
+
ri = 0
|
96
|
+
@backends.each do |b_sym|
|
97
|
+
ci = cgi
|
98
|
+
|
99
|
+
backend = eval "::Plist4r::Backend::#{b_sym.to_s.camelcase}"
|
100
|
+
if backend.respond_to? "from_#{fmt}"
|
101
|
+
failures = []
|
102
|
+
ref_strings[fmt].each_pair do |sym,string|
|
103
|
+
begin
|
104
|
+
plist_result = Plist4r.new :backends => [b_sym], :from_string => string
|
105
|
+
if @data_types.plists[sym].to_hash == plist_result.to_hash
|
106
|
+
puts "match, #{b_sym}, #{sym}" if sym == :data
|
107
|
+
# puts @data_types.plists[sym].hash.inspect
|
108
|
+
# puts plist_result.hash.inspect
|
109
|
+
# puts @data_types.plists[sym].to_hash["DataKeyW"].hash.inspect
|
110
|
+
# puts plist_result.to_hash["DataKeyW"].hash.inspect
|
111
|
+
else
|
112
|
+
puts "fail, #{b_sym}, #{sym}" if sym == :data
|
113
|
+
|
114
|
+
if sym == :data
|
115
|
+
puts "expected:"
|
116
|
+
puts @data_types.plists[sym].hash.inspect
|
117
|
+
puts @data_types.plists[sym].to_hash.inspect
|
118
|
+
# puts @data_types.plists[sym].to_hash["DataKeyW"].read.inspect
|
119
|
+
# @data_types.plists[sym].to_hash["DataKeyW"].rewind
|
120
|
+
# puts @data_types.plists[sym].to_hash["DataKeyW"].read.inspect
|
121
|
+
puts "got:"
|
122
|
+
puts plist_result.hash.inspect
|
123
|
+
puts plist_result.to_hash.inspect
|
124
|
+
# puts plist_result.to_xml if b_sym == "ruby_cocoa"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
rescue
|
128
|
+
puts "fail, #{b_sym}, #{sym} - exception"
|
129
|
+
failures << sym
|
130
|
+
end
|
131
|
+
end
|
132
|
+
if failures.empty?
|
133
|
+
time = Benchmark.measure { plist_result = Plist4r.new :backends => [b_sym], :from_string => ref_string_1024[fmt] }.real
|
134
|
+
tms = (time*1000).round(1).to_s
|
135
|
+
# puts " :from_#{fmt} - time for 1024 keys = " + (time*1000).round(1).to_s + " ms"
|
136
|
+
t.cell(ci, ri).content = "#{tms} ms"
|
137
|
+
else
|
138
|
+
t.cell(ci, ri).content = "Failed #{failures.inspect}"
|
139
|
+
end
|
140
|
+
|
141
|
+
else
|
142
|
+
# puts " not implemented, :from_#{fmt}"
|
143
|
+
t.cell(ci, ri).content = "n/a"
|
144
|
+
end
|
145
|
+
ci += 1
|
146
|
+
|
147
|
+
|
148
|
+
if backend.respond_to? "to_#{fmt}"
|
149
|
+
failures = []
|
150
|
+
@data_types.plists.each_pair do |sym,ref_plist|
|
151
|
+
begin
|
152
|
+
plist = Plist4r.new :backends => [b_sym]
|
153
|
+
plist.instance_eval "@hash = ref_plist.to_hash"
|
154
|
+
|
155
|
+
# puts "was: to_#{fmt}, #{b_sym} - #{sym.inspect}" if [:data, :bool].include?(sym)
|
156
|
+
# puts plist.to_binary.inspect if [:data, :bool].include?(sym)
|
157
|
+
# puts "should be:"
|
158
|
+
#
|
159
|
+
# puts "sepr char: #{plist.to_binary[20].chr.inspect}, last int #{plist.to_binary[20].inspect}," if sym == :data
|
160
|
+
# puts "last char: #{plist.to_binary[plist.to_binary.length-1].chr.inspect}, last int #{plist.to_binary[plist.to_binary.length-1].inspect}," if sym == :data
|
161
|
+
|
162
|
+
plist_gen_from = Plist4r.new :from_string => plist.send("to_#{fmt}"),
|
163
|
+
:backends => [reference_backend_for("from_#{fmt}".to_sym)]
|
164
|
+
|
165
|
+
if plist_gen_from.to_hash == plist.to_hash
|
166
|
+
puts "match, #{b_sym}, #{sym}" if sym == :data
|
167
|
+
# puts plist.hash.inspect
|
168
|
+
# puts plist_gen_from.hash.inspect
|
169
|
+
if sym == :data
|
170
|
+
if b_sym == "ruby_cocoa"
|
171
|
+
# plist_gen_from.to_hash.keys.each do |key|
|
172
|
+
# puts "point a"
|
173
|
+
# plist.to_hash.keys.each do |key|
|
174
|
+
# puts "key hash mismatch: #{key.inspect}" unless plist.to_hash[key].hash == plist_gen_from.to_hash[key].hash
|
175
|
+
# end
|
176
|
+
# puts "key hash mismatch: keys differ" unless plist.to_hash.keys == plist_gen_from.to_hash.keys
|
177
|
+
# puts "point b"
|
178
|
+
# puts plist.to_hash["DataKeyW"].hash.inspect
|
179
|
+
# puts plist_gen_from.to_hash["DataKeyW"].hash.inspect
|
180
|
+
|
181
|
+
|
182
|
+
# puts "expected:"
|
183
|
+
# puts plist.to_hash.inspect
|
184
|
+
# puts "got:"
|
185
|
+
# puts plist_gen_from.to_hash.inspect
|
186
|
+
end
|
187
|
+
end
|
188
|
+
else
|
189
|
+
puts "fail, #{b_sym}, #{sym}" if sym == :data
|
190
|
+
if sym == :data
|
191
|
+
puts "expected:"
|
192
|
+
puts plist.to_hash.inspect
|
193
|
+
puts "got:"
|
194
|
+
puts plist_gen_from.to_hash.inspect
|
195
|
+
end
|
196
|
+
end
|
197
|
+
rescue
|
198
|
+
puts "fail, #{b_sym}, #{sym} - exception"
|
199
|
+
|
200
|
+
begin
|
201
|
+
# what went wrong?
|
202
|
+
if fmt == :binary
|
203
|
+
puts "to_#{fmt}, #{b_sym} - for #{sym.inspect}. (1)was, (2)should be:"
|
204
|
+
plist = Plist4r.new :backends => [b_sym]
|
205
|
+
plist.instance_eval "@hash = ref_plist.to_hash"
|
206
|
+
puts plist.to_binary.inspect
|
207
|
+
|
208
|
+
plist = Plist4r.new :backends => [ReferenceBackends["to_#{fmt}".to_sym]]
|
209
|
+
plist.instance_eval "@hash = ref_plist.to_hash"
|
210
|
+
puts plist.to_binary.inspect
|
211
|
+
end
|
212
|
+
rescue
|
213
|
+
end
|
214
|
+
failures << sym
|
215
|
+
end
|
216
|
+
end
|
217
|
+
if failures.empty?
|
218
|
+
plist = Plist4r.new :backends => [b_sym]
|
219
|
+
plist_1024 = @data_types.plist_1024
|
220
|
+
plist.instance_eval "@hash = plist_1024.to_hash"
|
221
|
+
time = Benchmark.measure { eval "plist.to_#{fmt}" }.real
|
222
|
+
tms = (time*1000).round(1).to_s
|
223
|
+
# puts " :to_#{fmt} - time for 1024 keys = " + (time*1000).round(1).to_s + " ms"
|
224
|
+
t.cell(ci, ri).content = "#{tms} ms"
|
225
|
+
else
|
226
|
+
t.cell(ci, ri).content = "Failed #{failures.inspect}"
|
227
|
+
end
|
228
|
+
else
|
229
|
+
# puts " not implemented, :to_#{fmt}"
|
230
|
+
t.cell(ci, ri).content = "n/a"
|
231
|
+
end
|
232
|
+
|
233
|
+
# puts ""
|
234
|
+
ri += 1
|
235
|
+
end
|
236
|
+
|
237
|
+
cgi += 2
|
238
|
+
end
|
239
|
+
puts ""
|
240
|
+
puts "REFERENCE BACKENDS"
|
241
|
+
puts "=================="
|
242
|
+
ReferenceBackends.each do |sym,b_sym|
|
243
|
+
puts "#{sym.inspect} generated by #{b_sym.inspect}"
|
244
|
+
end
|
245
|
+
puts ""
|
246
|
+
puts t.inspect
|
247
|
+
@results = t
|
248
|
+
end
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
require 'plist4r/backend/test/harness'
|
3
|
+
|
4
|
+
module Plist4r
|
5
|
+
class Backend
|
6
|
+
module Test
|
7
|
+
class Output
|
8
|
+
|
9
|
+
def haml
|
10
|
+
@haml ||= <<-'EOC'
|
11
|
+
%h1 Backends
|
12
|
+
%div
|
13
|
+
%p Documentation for the Plist4r backend modules - please see <tt><a href="Plist4r/Backend.html" target="_self" title="Plist4r::Backend (class)">Plist4r::Backend</a></tt>
|
14
|
+
%h3 Performance
|
15
|
+
%p Time elapsed for encoding / decoding a non-flat (nested) plist structure of 1024 keys
|
16
|
+
%p Real elapsed time based on - 2GHz Intel Core Duo with 2GB Ram
|
17
|
+
%p Ruby Enterprise Edition (REE) 1.8.7 p248, Mac OS-X 10.6.3
|
18
|
+
= @test_harness.results
|
19
|
+
%p To re-run the backend tests
|
20
|
+
%pre{ :class => "code" } $ cd plist4r && rake backend:tests
|
21
|
+
%p
|
22
|
+
EOC
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
require 'haml'
|
27
|
+
engine = ::Haml::Engine.new self.haml
|
28
|
+
rendered_html_output = engine.render self
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize *args, &blk
|
32
|
+
@test_harness = Plist4r::Backend::Test::Harness.new
|
33
|
+
@test_harness.run_tests
|
34
|
+
end
|
35
|
+
|
36
|
+
def write_html_file
|
37
|
+
docs_dir = File.dirname(__FILE__) + "/../../../../lib/plist4r/docs"
|
38
|
+
File.open "#{docs_dir}/Backends.html","w" do |o|
|
39
|
+
o << to_s
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
data/lib/plist4r/backend_base.rb
CHANGED
@@ -2,7 +2,7 @@ require 'plist4r/mixin/mixlib_cli'
|
|
2
2
|
require 'plist4r/mixin/mixlib_config'
|
3
3
|
|
4
4
|
module Plist4r
|
5
|
-
# Defines options for the
|
5
|
+
# Defines options for the +plist4r+ command line utility
|
6
6
|
class CLI
|
7
7
|
include Plist4r::Mixlib::CLI
|
8
8
|
|
@@ -35,6 +35,7 @@ module Plist4r
|
|
35
35
|
end
|
36
36
|
plist4r_cli_options
|
37
37
|
|
38
|
+
# @yield Some block to yield
|
38
39
|
def parse argv=ARGV
|
39
40
|
parse_options(argv)
|
40
41
|
config
|
data/lib/plist4r/commands.rb
CHANGED
@@ -21,9 +21,10 @@ module Plist4r
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
# Implements the
|
24
|
+
# Implements the +plist4r --ruby-lib+ subcommand.
|
25
25
|
# @see Plist4r::CLI
|
26
26
|
def ruby_lib
|
27
|
+
plist4r_root = File.expand_path "../../", File.dirname(__FILE__)
|
27
28
|
plist4r_lib = File.expand_path "../../lib", File.dirname(__FILE__)
|
28
29
|
dest = File.expand_path(Plist4r::Config[:args][:dir] || FileUtils.pwd)
|
29
30
|
|
@@ -33,23 +34,27 @@ module Plist4r
|
|
33
34
|
FileUtils.mkdir_p dest
|
34
35
|
FileUtils.rm_rf "#{dest}/plist4r"
|
35
36
|
FileUtils.cp_r Dir.glob("#{plist4r_lib}/*"), dest
|
37
|
+
FileUtils.cp_r Dir.glob("#{plist4r_root}/VERSION"), "#{dest}/plist4r"
|
36
38
|
|
37
39
|
if Plist4r::Config[:args][:brew]
|
38
40
|
backends = Dir.glob "#{dest}/plist4r/backend/*"
|
41
|
+
docs = Dir.glob "#{dest}/plist4r/docs*"
|
42
|
+
haml4r = Dir.glob "#{dest}/plist4r/mixin/haml4r*"
|
39
43
|
non_brew_files = [
|
44
|
+
"#{dest}/plist4r/application.rb",
|
40
45
|
backends - ["#{dest}/plist4r/backend/ruby_cocoa.rb"],
|
41
|
-
"#{dest}/plist4r/
|
42
|
-
"#{dest}/plist4r/options.rb",
|
46
|
+
"#{dest}/plist4r/cli.rb",
|
43
47
|
"#{dest}/plist4r/commands.rb",
|
44
|
-
|
45
|
-
|
48
|
+
docs,
|
49
|
+
haml4r,
|
50
|
+
"#{dest}/plist4r/mixin/mixlib_cli.rb",
|
51
|
+
"#{dest}/plist4r/mixin/script.rb",
|
52
|
+
"#{dest}/plist4r/mixin/table.rb",
|
46
53
|
].flatten
|
47
54
|
FileUtils.rm_rf(non_brew_files)
|
48
55
|
|
49
56
|
config = File.read "#{dest}/plist4r/config.rb"
|
50
|
-
config.gsub!
|
51
|
-
"\n#{$1}backends [\"ruby_cocoa\"]#{$2}\n"
|
52
|
-
end
|
57
|
+
config.gsub! /backends default_backends/,"backends default_backends :brew"
|
53
58
|
|
54
59
|
File.open("#{dest}/plist4r/config.rb",'w') do |o|
|
55
60
|
o << config
|
data/lib/plist4r/config.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
|
2
2
|
require 'plist4r/mixin/mixlib_config'
|
3
3
|
require 'plist4r/backend'
|
4
|
-
|
4
|
+
|
5
|
+
Dir.glob(File.dirname(__FILE__) + "/backend/*.rb").each {|b| require File.expand_path b}
|
5
6
|
|
6
7
|
module Plist4r
|
7
8
|
|
@@ -12,10 +13,10 @@ module Plist4r
|
|
12
13
|
# Plist4r::Config[:backends].reverse!
|
13
14
|
#
|
14
15
|
# # Set the default folder from which to load / save plist files
|
15
|
-
# Plist4r::Config[:default_path] "/path/to/my/plist/files"
|
16
|
+
# Plist4r::Config[:default_path] = "/path/to/my/plist/files"
|
16
17
|
#
|
17
18
|
# # Save new plist files as binary plists (when format not known)
|
18
|
-
# Plist4r::Config[:default_format] :binary
|
19
|
+
# Plist4r::Config[:default_format] = :binary
|
19
20
|
#
|
20
21
|
# # Add custom / application specific Plist Type. You'll also need to subclass {Plist4r::PlistType}
|
21
22
|
# Expects class Plist4r::PlistType::MyPlistType to be defined
|
@@ -23,20 +24,46 @@ module Plist4r
|
|
23
24
|
# Plist4r::Config[:types] << "my_plist_type"
|
24
25
|
#
|
25
26
|
# # Raise an exception plist keys which dont belong to the selected Plist type
|
26
|
-
# Plist4r::Config[:strict_keys] true
|
27
|
+
# Plist4r::Config[:strict_keys] = true
|
27
28
|
class Config
|
28
29
|
extend Mixlib::Config
|
29
30
|
|
30
|
-
|
31
|
+
CoreFoundationFramework = "/System/Library/Frameworks/CoreFoundation.framework"
|
32
|
+
RubycocoaFramework = "/System/Library/Frameworks/RubyCocoa.framework"
|
33
|
+
|
34
|
+
DefaultBackendsAny = ["c_f_property_list","haml","libxml4r"]
|
35
|
+
DefaultBackendsOsx = ["osx_plist","c_f_property_list","haml","libxml4r"]
|
36
|
+
|
37
|
+
def self.default_backends sym=nil
|
38
|
+
case sym
|
39
|
+
when :brew
|
40
|
+
["ruby_cocoa"]
|
41
|
+
else
|
42
|
+
if File.exists? CoreFoundationFramework
|
43
|
+
if File.exists? RubycocoaFramework
|
44
|
+
DefaultBackendsOsx + ["ruby_cocoa"]
|
45
|
+
else
|
46
|
+
DefaultBackendsOsx
|
47
|
+
end
|
48
|
+
else
|
49
|
+
DefaultBackendsAny
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
types [] << Dir.glob(File.dirname(__FILE__) + "/plist_type/*.rb").collect {|b| File.basename(b,".rb") }
|
31
55
|
types.flatten!.uniq!
|
32
56
|
|
33
|
-
backends
|
34
|
-
backends << Dir.glob(File.dirname(__FILE__) + "/backend
|
57
|
+
backends default_backends
|
58
|
+
backends << Dir.glob(File.dirname(__FILE__) + "/backend/*.rb").collect {|b| File.basename(b,".rb") }
|
35
59
|
backends.flatten!.uniq!
|
60
|
+
backends.delete "example"
|
61
|
+
|
62
|
+
backend_timeout 15
|
36
63
|
|
37
64
|
strict_keys false
|
38
|
-
raise_any_failure
|
39
|
-
|
65
|
+
raise_any_failure false
|
66
|
+
default_format :xml
|
40
67
|
default_path nil
|
41
68
|
end
|
42
69
|
end
|