plist4r 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -21,6 +21,8 @@ pkg
21
21
  ## PROJECT::SPECIFIC
22
22
  .yardoc
23
23
  doc
24
+ ext/osx_plist/plist.o
25
+ ext/osx_plist/Makefile
24
26
 
25
27
  # Ruby
26
28
  *.bundle
data/Rakefile CHANGED
@@ -51,13 +51,24 @@ end
51
51
 
52
52
  task :default => :spec
53
53
 
54
- namespace :backend do
55
- task :tests do
54
+ namespace :backends do
55
+ task :compile do
56
+ if File.exists? "/System/Library/Frameworks/CoreFoundation.framework"
57
+ r = %x[rm ext/osx_plist/osx_plist.bundle lib/plist4r/backend/osx_plist/ext/osx_plist.bundle]
58
+ puts r if r.length > 0
59
+ puts %x[cd ext/osx_plist && ./extconf.rb && make clean && make]
60
+ r = %x[cp ext/osx_plist/osx_plist.bundle lib/plist4r/backend/osx_plist/ext/osx_plist.bundle]
61
+ puts r if r.length > 0
62
+ end
63
+ end
64
+
65
+ task :test => :compile do
56
66
  require 'lib/plist4r'
57
67
  require 'plist4r/backend/test/output'
58
68
  o = Plist4r::Backend::Test::Output.new
59
69
  puts o
60
70
  o.write_html_file
71
+ o.results_stdout
61
72
  end
62
73
  end
63
74
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.1.0
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  if File.exists? "/System/Library/Frameworks/CoreFoundation.framework"
4
4
  require 'mkmf'
data/lib/plist4r.rb CHANGED
@@ -42,6 +42,11 @@ module Plist4r
42
42
  # @example
43
43
  # Plist4r.string_detect_format("{ \"key1\" = \"value1\"; \"key2\" = \"value2\"; }") => :gnustep
44
44
  def string_detect_format string
45
+ if RUBY_VERSION >= '1.9'
46
+ string = string.force_encoding(Encoding::ASCII_8BIT)
47
+ end
48
+
49
+
45
50
  string.strip! if string[0,1] =~ /\s/
46
51
  case string[0,1]
47
52
  when "{","("
@@ -3,6 +3,7 @@
3
3
  require 'libxml'
4
4
  require 'kconv'
5
5
  require 'date'
6
+ require 'time'
6
7
 
7
8
  #
8
9
  # CFPropertyList implementation
@@ -3,7 +3,7 @@ require 'plist4r/backend_base'
3
3
  require 'plist4r/mixin/ruby_stdlib'
4
4
  require 'haml'
5
5
  require 'base64'
6
- require 'date'
6
+ require 'time'
7
7
 
8
8
  # This backend uses haml to generate xml plists
9
9
  # @author Dreamcat4 (dreamcat4@gmail.com)
@@ -39,9 +39,6 @@ module Plist4r::Backend::Haml
39
39
  - when Time
40
40
  %key #{k}
41
41
  %date #{v.utc.strftime('%Y-%m-%dT%H:%M:%SZ')}
42
- - when Date
43
- %key #{k}
44
- %date #{v.strftime('%Y-%m-%dT%H:%M:%SZ')}
45
42
  - when Array
46
43
  %key #{k}
47
44
  %array
@@ -61,8 +58,6 @@ module Plist4r::Backend::Haml
61
58
  %real #{e}
62
59
  - when Time
63
60
  %date #{e.utc.strftime('%Y-%m-%dT%H:%M:%SZ')}
64
- - when Date
65
- %date #{e.strftime('%Y-%m-%dT%H:%M:%SZ')}
66
61
  - when Hash
67
62
  %dict
68
63
  - tab_up ; block.call(e, block) ; tab_down
@@ -2,7 +2,7 @@
2
2
  require 'plist4r/backend_base'
3
3
  require 'libxml4r'
4
4
  require 'base64'
5
- require 'date'
5
+ require 'time'
6
6
 
7
7
  # This backend uses Libxml4r / Libxml-Ruby to parse xml plists
8
8
  # @author Dreamcat4 (dreamcat4@gmail.com)
@@ -1,8 +1,10 @@
1
1
 
2
2
  require 'plist4r/backend_base'
3
3
  require 'plist4r/mixin/ruby_stdlib'
4
+ require 'time'
4
5
 
5
6
  module Plist4r
7
+ # @private
6
8
  class StringIOData
7
9
  attr_accessor :string
8
10
  def initialize string
@@ -26,6 +28,7 @@ module Plist4r
26
28
  end
27
29
 
28
30
  class String
31
+ # @private
29
32
  def _dump arg
30
33
  if self.blob?
31
34
  string_io_data = Plist4r::StringIOData.new(self)
@@ -35,6 +38,7 @@ class String
35
38
  end
36
39
  end
37
40
 
41
+ # @private
38
42
  def self._load string
39
43
  String.new string
40
44
  end
@@ -64,7 +68,7 @@ dir = ARGV[0]
64
68
  $LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
65
69
 
66
70
  require 'osx/cocoa'
67
- require 'date'
71
+ require 'time'
68
72
  require 'plist4r/mixin/ordered_hash'
69
73
  require 'plist4r/mixin/ruby_stdlib'
70
74
 
@@ -138,7 +142,7 @@ class OSX::NSObject
138
142
  when OSX::NSArray
139
143
  self.to_a.map { |x| x.is_a?(OSX::NSObject) ? x.to_ruby : x }
140
144
  when OSX::NSDictionary
141
- h = ::Plist4r::OrderedHash.new
145
+ h = Plist4r::ActiveSupport::OrderedHash.new
142
146
  self.each do |x, y|
143
147
  x = x.to_ruby if x.is_a?(OSX::NSObject)
144
148
  y = y.to_ruby if y.is_a?(OSX::NSObject)
@@ -162,6 +166,7 @@ module Plist
162
166
  # to_plist defaults to NSPropertyListXMLFormat_v1_0
163
167
  hash = Marshal.load(File.read(input_file))
164
168
  x = hash.to_plist
169
+ # x = hash.inspect
165
170
  write_result_file x
166
171
  end
167
172
 
@@ -169,6 +174,7 @@ module Plist
169
174
  # Here 200 == NSPropertyListBinaryFormat_v1_0
170
175
  hash = Marshal.load(File.read(input_file))
171
176
  x = hash.to_plist 200
177
+ # x = hash.inspect
172
178
  write_result_file x
173
179
  end
174
180
 
@@ -177,7 +183,7 @@ module Plist
177
183
  unless plist_dict
178
184
  plist_array = ::OSX::NSArray.arrayWithContentsOfFile(filename) unless plist_dict
179
185
  raise "Couldnt parse file: #{filename}" unless plist_array
180
- plist_dict = ::Plist4r::OrderedHash.new
186
+ plist_dict = Plist4r::ActiveSupport::OrderedHash.new
181
187
  plist_dict["Array"] = plist_array.to_ruby
182
188
  end
183
189
 
@@ -253,13 +259,36 @@ EOC
253
259
  File.read @result_file.path
254
260
  end
255
261
 
262
+ def convert_19_to_hash hash, key=nil
263
+ h = Hash.new
264
+ h.replace hash
265
+
266
+ hash.each do |key,value|
267
+ if value.class.ancestors.include? Hash
268
+ unless value.class == Hash
269
+ h[key] = convert_19_to_hash(value)
270
+ end
271
+ end
272
+ end
273
+ h
274
+ end
275
+
256
276
  def to_xml plist
257
277
  require 'tempfile'
258
278
  input_file = Tempfile.new "input_file.rb."
259
- input_file.puts Marshal.dump(plist.to_hash)
279
+
280
+ oh = nil
281
+ if RUBY_VERSION >= '1.9'
282
+ old_style_hash = convert_19_to_hash(plist.to_hash)
283
+ input_file.puts Marshal.dump(old_style_hash)
284
+ else
285
+ input_file.puts Marshal.dump(plist.to_hash)
286
+ end
287
+
260
288
  input_file.close
261
289
  result = ruby_cocoa_exec "to_xml(\"#{input_file.path}\")"
262
-
290
+ # print read_result_file
291
+
263
292
  case result[1].exitstatus
264
293
  when 0
265
294
  xml_string = read_result_file
@@ -273,9 +302,17 @@ EOC
273
302
  def to_binary plist
274
303
  require 'tempfile'
275
304
  input_file = Tempfile.new "input_file.rb."
276
- input_file.puts Marshal.dump(plist.to_hash)
305
+
306
+ if RUBY_VERSION >= '1.9'
307
+ old_style_hash = convert_19_to_hash(plist.to_hash)
308
+ input_file.puts Marshal.dump(old_style_hash)
309
+ else
310
+ input_file.puts Marshal.dump(plist.to_hash)
311
+ end
312
+
277
313
  input_file.close
278
314
  result = ruby_cocoa_exec "to_binary(\"#{input_file.path}\")"
315
+ # print read_result_file
279
316
 
280
317
  case result[1].exitstatus
281
318
  when 0
@@ -288,12 +325,11 @@ EOC
288
325
  end
289
326
 
290
327
  def open_with_args plist, filename
291
- require 'date'
292
-
293
328
  result = ruby_cocoa_exec "open(\"#{filename}\")"
294
329
  case result[1].exitstatus
295
330
  when 0
296
- hash = ::Plist4r::OrderedHash.new
331
+ hash = Plist4r::OrderedHash.new
332
+
297
333
  hash.replace Marshal.load(read_result_file)
298
334
  plist.import_hash hash
299
335
  else
@@ -54,7 +54,7 @@ module Plist4r
54
54
  end
55
55
 
56
56
  def gen_time
57
- require 'date'
57
+ require 'time'
58
58
  (0..25).each do |i|
59
59
  @plist.store "DateKey#{(65+i).chr}", Time.parse("2010-04-#{sprintf("%.2i",i+1)}T19:50:01Z")
60
60
  end
@@ -85,6 +85,7 @@ module Plist4r
85
85
  def gen_hash
86
86
  (0..25).each do |i|
87
87
  h = Plist4r::OrderedHash.new
88
+ # (0..0).each do |j|
88
89
  (0..i).each do |j|
89
90
  h["String#{(65+j).chr}"] = "#{(97+j).chr}"*(j+1)
90
91
  end
@@ -27,8 +27,8 @@ module Plist4r
27
27
  :to_binary => :c_f_property_list,
28
28
  # :from_binary => :ruby_cocoa,
29
29
  # :to_binary => :ruby_cocoa,
30
- :from_binary => :osx_plist,
31
- :to_binary => :osx_plist,
30
+ # :from_binary => :osx_plist,
31
+ # :to_binary => :osx_plist,
32
32
  }
33
33
 
34
34
  def reference_backend_for meth
@@ -103,23 +103,19 @@ module Plist4r
103
103
  begin
104
104
  plist_result = Plist4r.new :backends => [b_sym], :from_string => string
105
105
  if @data_types.plists[sym].to_hash == plist_result.to_hash
106
- puts "match, #{b_sym}, #{sym}" if sym == :data
106
+ puts "match, #{b_sym}, #{sym}"
107
107
  # puts @data_types.plists[sym].hash.inspect
108
- # puts plist_result.hash.inspect
109
108
  # puts @data_types.plists[sym].to_hash["DataKeyW"].hash.inspect
110
109
  # puts plist_result.to_hash["DataKeyW"].hash.inspect
111
110
  else
112
- puts "fail, #{b_sym}, #{sym}" if sym == :data
111
+ puts "fail, #{b_sym}, #{sym}"
112
+ failures << sym
113
113
 
114
- if sym == :data
114
+ if true
115
115
  puts "expected:"
116
116
  puts @data_types.plists[sym].hash.inspect
117
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
118
  puts "got:"
122
- puts plist_result.hash.inspect
123
119
  puts plist_result.to_hash.inspect
124
120
  # puts plist_result.to_xml if b_sym == "ruby_cocoa"
125
121
  end
@@ -163,10 +159,10 @@ module Plist4r
163
159
  :backends => [reference_backend_for("from_#{fmt}".to_sym)]
164
160
 
165
161
  if plist_gen_from.to_hash == plist.to_hash
166
- puts "match, #{b_sym}, #{sym}" if sym == :data
162
+ puts "match, #{b_sym}, #{sym}"
167
163
  # puts plist.hash.inspect
168
164
  # puts plist_gen_from.hash.inspect
169
- if sym == :data
165
+ # if sym == :data
170
166
  if b_sym == "ruby_cocoa"
171
167
  # plist_gen_from.to_hash.keys.each do |key|
172
168
  # puts "point a"
@@ -182,21 +178,26 @@ module Plist4r
182
178
  # puts "expected:"
183
179
  # puts plist.to_hash.inspect
184
180
  # puts "got:"
181
+ # puts plist.send("to_#{fmt}")
185
182
  # puts plist_gen_from.to_hash.inspect
186
183
  end
187
- end
184
+ # end
188
185
  else
189
- puts "fail, #{b_sym}, #{sym}" if sym == :data
190
- if sym == :data
186
+ puts "fail, #{b_sym}, #{sym}"
187
+ failures << sym
188
+ if true
191
189
  puts "expected:"
192
190
  puts plist.to_hash.inspect
193
191
  puts "got:"
194
192
  puts plist_gen_from.to_hash.inspect
193
+ puts "got:"
194
+ puts plist.send("to_#{fmt}")
195
195
  end
196
196
  end
197
197
  rescue
198
198
  puts "fail, #{b_sym}, #{sym} - exception"
199
-
199
+ # puts $!.inspect if b_sym == :ruby_cocoa
200
+ raise
200
201
  begin
201
202
  # what went wrong?
202
203
  if fmt == :binary
@@ -211,6 +212,7 @@ module Plist4r
211
212
  end
212
213
  rescue
213
214
  end
215
+ # raise if b_sym == :ruby_cocoa
214
216
  failures << sym
215
217
  end
216
218
  end
@@ -237,18 +239,9 @@ module Plist4r
237
239
  cgi += 2
238
240
  end
239
241
  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
242
  @results = t
248
243
  end
249
244
 
250
-
251
-
252
245
  end
253
246
  end
254
247
  end
@@ -17,7 +17,7 @@ module Plist4r
17
17
  %p Ruby Enterprise Edition (REE) 1.8.7 p248, Mac OS-X 10.6.3
18
18
  = @test_harness.results
19
19
  %p To re-run the backend tests
20
- %pre{ :class => "code" } $ cd plist4r && rake backend:tests
20
+ %pre{ :class => "code" } $ cd plist4r && rake backends:test
21
21
  %p
22
22
  EOC
23
23
  end
@@ -40,6 +40,17 @@ EOC
40
40
  end
41
41
  end
42
42
 
43
+ def results_stdout
44
+ puts ""
45
+ puts "REFERENCE BACKENDS"
46
+ puts "=================="
47
+ Plist4r::Backend::Test::Harness::ReferenceBackends.each do |sym,b_sym|
48
+ puts "#{sym.inspect} generated by #{b_sym.inspect}"
49
+ end
50
+ puts ""
51
+ puts @test_harness.results.inspect
52
+ puts ""
53
+ end
43
54
  end
44
55
  end
45
56
  end
@@ -18,42 +18,42 @@
18
18
  <tbody>
19
19
  <tr>
20
20
  <th style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #F5F5FF; text-align: right'>c_f_property_list</th>
21
- <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>18.2 ms</td>
22
- <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>19.5 ms</td>
23
- <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>33.4 ms</td>
24
- <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>34.9 ms</td>
21
+ <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>26.2 ms</td>
22
+ <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>36.1 ms</td>
23
+ <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>15.5 ms</td>
24
+ <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>67.7 ms</td>
25
25
  </tr>
26
26
  <tr>
27
27
  <th style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #F5F5FF; text-align: right'>haml</th>
28
28
  <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>n/a</td>
29
- <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>126.8 ms</td>
29
+ <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>30.3 ms</td>
30
30
  <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>n/a</td>
31
31
  <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>n/a</td>
32
32
  </tr>
33
33
  <tr>
34
34
  <th style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #F5F5FF; text-align: right'>libxml4r</th>
35
- <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>41.4 ms</td>
35
+ <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>57.2 ms</td>
36
36
  <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>n/a</td>
37
37
  <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>n/a</td>
38
38
  <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>n/a</td>
39
39
  </tr>
40
40
  <tr>
41
41
  <th style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #F5F5FF; text-align: right'>osx_plist</th>
42
- <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>4.8 ms</td>
43
- <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>5.0 ms</td>
44
- <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>4.6 ms</td>
45
- <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>4.6 ms</td>
42
+ <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>6.0 ms</td>
43
+ <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>17.8 ms</td>
44
+ <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>3.6 ms</td>
45
+ <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>5.4 ms</td>
46
46
  </tr>
47
47
  <tr>
48
48
  <th style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #F5F5FF; text-align: right'>ruby_cocoa</th>
49
- <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>320.4 ms</td>
50
- <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>318.8 ms</td>
51
- <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>319.7 ms</td>
52
- <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>319.2 ms</td>
49
+ <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>297.9 ms</td>
50
+ <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>267.4 ms</td>
51
+ <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>288.4 ms</td>
52
+ <td style='padding: 5px; padding-left: 15px; padding-right: 15px; background-color: #FAFAFA; text-align: center'>264.0 ms</td>
53
53
  </tr>
54
54
  </tbody>
55
55
  </table>
56
56
  <p>To re-run the backend tests</p>
57
- <pre class='code'>$ cd plist4r && rake backend:tests</pre>
57
+ <pre class='code'>$ cd plist4r && rake backends:test</pre>
58
58
  </div>
59
59
  <p></p>
@@ -36,7 +36,7 @@ We re-use common support objects when writing a new PlistType
36
36
  For a change in the {Plist4r} Core library
37
37
 
38
38
  * Please update the inline source code documentation, generate locally with +rake yard+
39
- * Please run the regression tests with +rake spec+ and +rake backend:tests+
39
+ * Please run the regression tests with +rake spec+ and +rake backends:test+
40
40
  * Please update the existing regression tests (in RSpec) or write new ones
41
41
 
42
42
  For a {Plist4r::Backend}
@@ -1,185 +1,191 @@
1
1
 
2
2
  module Plist4r
3
3
  module ActiveSupport
4
- # Hash is ordered in Ruby 1.9!
5
- unless RUBY_VERSION >= '1.9'
6
- # {ActiveSupport::OrderedHash}
7
- #
8
- # Copyright (c) 2005 David Hansson,
9
- #
10
- # Copyright (c) 2007 Mauricio Fernandez, Sam Stephenson
11
- #
12
- # Copyright (c) 2008 Steve Purcell, Josh Peek
13
- #
14
- # Copyright (c) 2009 Christoffer Sawicki
15
- #
16
- # Permission is hereby granted, free of charge, to any person obtaining
17
- # a copy of this software and associated documentation files (the
18
- # "Software"), to deal in the Software without restriction, including
19
- # without limitation the rights to use, copy, modify, merge, publish,
20
- # distribute, sublicense, and/or sell copies of the Software, and to
21
- # permit persons to whom the Software is furnished to do so, subject to
22
- # the following conditions:
23
- #
24
- # The above copyright notice and this permission notice shall be
25
- # included in all copies or substantial portions of the Software.
26
- #
27
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
- #
35
- class OrderedHash < Hash
36
- def initialize(*args, &block)
37
- super
38
- @keys = []
39
- end
40
-
41
- def self.[](*args)
42
- ordered_hash = new
43
-
44
- if (args.length == 1 && args.first.is_a?(Array))
45
- args.first.each do |key_value_pair|
46
- next unless (key_value_pair.is_a?(Array))
47
- ordered_hash[key_value_pair[0]] = key_value_pair[1]
48
- end
49
-
50
- return ordered_hash
51
- end
4
+ # ActiveSupport::OrderedHash
5
+ #
6
+ # Copyright (c) 2005 David Hansson,
7
+ #
8
+ # Copyright (c) 2007 Mauricio Fernandez, Sam Stephenson
9
+ #
10
+ # Copyright (c) 2008 Steve Purcell, Josh Peek
11
+ #
12
+ # Copyright (c) 2009 Christoffer Sawicki
13
+ #
14
+ # Permission is hereby granted, free of charge, to any person obtaining
15
+ # a copy of this software and associated documentation files (the
16
+ # "Software"), to deal in the Software without restriction, including
17
+ # without limitation the rights to use, copy, modify, merge, publish,
18
+ # distribute, sublicense, and/or sell copies of the Software, and to
19
+ # permit persons to whom the Software is furnished to do so, subject to
20
+ # the following conditions:
21
+ #
22
+ # The above copyright notice and this permission notice shall be
23
+ # included in all copies or substantial portions of the Software.
24
+ #
25
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
+ #
33
+ class OrderedHash < Hash
34
+ def initialize(*args, &block)
35
+ super
36
+ @keys = []
37
+ end
52
38
 
53
- unless (args.size % 2 == 0)
54
- raise ArgumentError.new("odd number of arguments for Hash")
55
- end
39
+ def self.[](*args)
40
+ ordered_hash = new
56
41
 
57
- args.each_with_index do |val, ind|
58
- next if (ind % 2 != 0)
59
- ordered_hash[val] = args[ind + 1]
42
+ if (args.length == 1 && args.first.is_a?(Array))
43
+ args.first.each do |key_value_pair|
44
+ next unless (key_value_pair.is_a?(Array))
45
+ ordered_hash[key_value_pair[0]] = key_value_pair[1]
60
46
  end
61
47
 
62
- ordered_hash
48
+ return ordered_hash
63
49
  end
64
50
 
65
- def initialize_copy(other)
66
- super
67
- # make a deep copy of keys
68
- @keys = other.keys
51
+ unless (args.size % 2 == 0)
52
+ raise ArgumentError.new("odd number of arguments for Hash")
69
53
  end
70
54
 
71
- def store(key, value)
72
- @keys << key if !has_key?(key)
73
- super
55
+ args.each_with_index do |val, ind|
56
+ next if (ind % 2 != 0)
57
+ ordered_hash[val] = args[ind + 1]
74
58
  end
75
59
 
76
- def []=(key, value)
77
- @keys << key if !has_key?(key)
78
- super
79
- end
60
+ ordered_hash
61
+ end
80
62
 
81
- def delete(key)
82
- if has_key? key
83
- index = @keys.index(key)
84
- @keys.delete_at index
85
- end
86
- super
87
- end
63
+ def initialize_copy(other)
64
+ super
65
+ # make a deep copy of keys
66
+ @keys = other.keys
67
+ end
88
68
 
89
- def delete_if
90
- super
91
- sync_keys!
92
- self
93
- end
69
+ def store(key, value)
70
+ @keys << key if !has_key?(key)
71
+ super
72
+ end
94
73
 
95
- def reject!
96
- super
97
- sync_keys!
98
- self
99
- end
74
+ def []=(key, value)
75
+ @keys << key if !has_key?(key)
76
+ super
77
+ end
100
78
 
101
- def reject(&block)
102
- dup.reject!(&block)
79
+ def delete(key)
80
+ if has_key? key
81
+ index = @keys.index(key)
82
+ @keys.delete_at index
103
83
  end
84
+ super
85
+ end
104
86
 
105
- def keys
106
- @keys.dup
107
- end
87
+ def delete_if
88
+ super
89
+ sync_keys!
90
+ self
91
+ end
108
92
 
109
- def values
110
- @keys.collect { |key| self[key] }
111
- end
93
+ def reject!
94
+ super
95
+ sync_keys!
96
+ self
97
+ end
112
98
 
113
- def to_hash
114
- self
115
- end
99
+ def reject(&block)
100
+ dup.reject!(&block)
101
+ end
116
102
 
117
- def to_a
118
- @keys.map { |key| [ key, self[key] ] }
119
- end
103
+ def keys
104
+ (@keys || []).dup
105
+ end
120
106
 
121
- def each_key
122
- @keys.each { |key| yield key }
123
- end
107
+ def values
108
+ @keys.collect { |key| self[key] }
109
+ end
124
110
 
125
- def each_value
126
- @keys.each { |key| yield self[key]}
127
- end
111
+ def to_hash
112
+ self
113
+ end
128
114
 
129
- def each
130
- @keys.each {|key| yield [key, self[key]]}
131
- end
115
+ def to_a
116
+ @keys.map { |key| [ key, self[key] ] }
117
+ end
132
118
 
133
- alias_method :each_pair, :each
119
+ def each_key
120
+ @keys.each { |key| yield key }
121
+ end
134
122
 
135
- def clear
136
- super
137
- @keys.clear
138
- self
139
- end
123
+ def each_value
124
+ @keys.each { |key| yield self[key]}
125
+ end
140
126
 
141
- def shift
142
- k = @keys.first
143
- v = delete(k)
144
- [k, v]
145
- end
127
+ def each
128
+ @keys.each {|key| yield [key, self[key]]}
129
+ end
146
130
 
147
- def merge!(other_hash)
148
- other_hash.each {|k,v| self[k] = v }
149
- self
150
- end
131
+ alias_method :each_pair, :each
151
132
 
152
- def merge(other_hash)
153
- dup.merge!(other_hash)
154
- end
133
+ def clear
134
+ super
135
+ @keys.clear
136
+ self
137
+ end
155
138
 
156
- # When replacing with another hash, the initial order of our keys must come from the other hash -ordered or not.
157
- def replace(other)
158
- super
159
- @keys = other.keys
160
- self
161
- end
139
+ def shift
140
+ k = @keys.first
141
+ v = delete(k)
142
+ [k, v]
143
+ end
162
144
 
163
- # This breaks passing the Hash through Stdin to RubyCocoa
164
- # def inspect
165
- # "#<OrderedHash #{super}>"
166
- # end
145
+ def merge!(other_hash)
146
+ other_hash.each {|k,v| self[k] = v }
147
+ self
148
+ end
167
149
 
168
- private
150
+ def merge(other_hash)
151
+ dup.merge!(other_hash)
152
+ end
169
153
 
170
- def sync_keys!
171
- @keys.delete_if {|k| !has_key?(k)}
172
- end
154
+ # When replacing with another hash, the initial order of our keys must come from the other hash -ordered or not.
155
+ def replace(other)
156
+ super
157
+ @keys = other.keys
158
+ self
173
159
  end
174
- else
175
- class OrderedHash < ::Hash
160
+
161
+ def inspect
162
+ "#<OrderedHash #{super}>"
163
+ end
164
+
165
+ private
166
+
167
+ def sync_keys!
168
+ @keys.delete_if {|k| !has_key?(k)}
176
169
  end
177
170
  end
178
171
  end
179
172
  end
180
173
 
181
174
  module Plist4r
182
- # This is an {ActiveSupport::OrderedHash}
183
- class OrderedHash < ActiveSupport::OrderedHash
175
+ if RUBY_VERSION >= '1.9'
176
+ # Inheritance
177
+ # Ruby 1.9 < Hash
178
+ # Ruby 1.8 < ActiveSupport::OrderedHash
179
+ class OrderedHash < ::Hash
180
+ end
181
+ else
182
+ # Inheritance
183
+ # Ruby 1.9 < Hash
184
+ # Ruby 1.8 < ActiveSupport::OrderedHash
185
+ class OrderedHash < Plist4r::ActiveSupport::OrderedHash
186
+ end
184
187
  end
185
188
  end
189
+
190
+
191
+
@@ -70,6 +70,23 @@ class Array
70
70
  end
71
71
 
72
72
  class Hash
73
+ # Merge together an array of complex hash structures
74
+ # @example
75
+ # @aohoa1 = {}
76
+ #
77
+ # @aohoa2 = [
78
+ # { :array1 => [:a], :array2 => [:a,:b], :array3 => [:a,:b,:c] },
79
+ # { :array1 => [:aa], :array2 => [:aa,:bb], :array3 => [:aa,:bb,:cc] },
80
+ # { :array1 => [:aaa], :array2 => [:aaa,:bbb], :array3 => [:aaa,:bbb,:ccc] }
81
+ # ]
82
+ #
83
+ # @aohoa1.merge_array_of_hashes_of_arrays(@aohoa2)
84
+ # => {
85
+ # :array1 => [:a,:aa,:aaa],
86
+ # :array2 => [:a,:b,:aa,:bb,:aaa,:bbb],
87
+ # :array3 => [:a,:b,:c,:aa,:bb,:cc,:aaa,:bbb,:ccc]
88
+ # }
89
+ # @see Plist4r::PlistType::Info::ValidKeys
73
90
  def merge_array_of_hashes_of_arrays array_of_hashes_of_arrays
74
91
  a = array_of_hashes_of_arrays
75
92
  raise "not an array_of_hashes_of_arrays" unless a.is_a? Array
@@ -88,6 +105,7 @@ class Hash
88
105
  h
89
106
  end
90
107
 
108
+ # @see #merge_array_of_hashes_of_arrays
91
109
  def merge_array_of_hashes_of_arrays! array_of_hashes_of_arrays
92
110
  h = merge_array_of_hashes_of_arrays array_of_hashes_of_arrays
93
111
  self.replace h
@@ -186,6 +204,11 @@ class Float
186
204
  # @example
187
205
  # 16.347.round(2) => 16.35
188
206
  def round(n=0)
189
- (self * (10.0 ** n)).round_orig * (10.0 ** (-n))
207
+ sprintf("%#{n}.#{n}f", self).to_f
190
208
  end
191
209
  end
210
+
211
+
212
+
213
+
214
+
data/lib/plist4r/plist.rb CHANGED
@@ -73,7 +73,7 @@ module Plist4r
73
73
  def from_string string=nil
74
74
  case string
75
75
  when String
76
- plist_format = ::Plist4r.string_detect_format(string)
76
+ plist_format = Plist4r.string_detect_format(string)
77
77
  if plist_format
78
78
  @from_string = string
79
79
  @plist_cache ||= PlistCache.new self
@@ -344,12 +344,12 @@ module Plist4r
344
344
  # @see Backend::Example
345
345
  def import_hash hash=nil
346
346
  case hash
347
- when ::Plist4r::OrderedHash
347
+ when Plist4r::OrderedHash
348
348
  @hash = hash
349
349
  when nil
350
350
  @hash = ::Plist4r::OrderedHash.new
351
351
  else
352
- raise "Please use ::Plist4r::OrderedHash.new for your hashes"
352
+ raise "Please use Plist4r::OrderedHash.new for your hashes"
353
353
  end
354
354
  end
355
355
 
@@ -392,11 +392,17 @@ module Plist4r
392
392
  # @yield Keep every key-value pair for which the passed block evaluates to true. Works as per the ruby core classes Hash#select method
393
393
  def select *keys, &blk
394
394
  if block_given?
395
- a = @hash.select &blk
395
+ selection = @hash.select &blk
396
396
  old_hash = @hash.deep_clone
397
397
  clear
398
- a.each do |pair|
399
- store pair[0], pair[1]
398
+ if RUBY_VERSION >= '1.9'
399
+ selection.each do |key,value|
400
+ store key, value
401
+ end
402
+ else
403
+ selection.each do |pair|
404
+ store pair[0], pair[1]
405
+ end
400
406
  end
401
407
  keys.each do |k|
402
408
  store k, old_hash[k]
data/plist4r.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{plist4r}
8
- s.version = "1.0.1"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["dreamcat4"]
12
- s.date = %q{2010-07-20}
12
+ s.date = %q{2010-07-21}
13
13
  s.default_executable = %q{plist4r}
14
14
  s.description = %q{Plist4r is for editing Plist files in an easy-to-use, fast, and reliabile way. A comprehensive and fully featured Ruby library. Xml and Binary file formats are supported, with backends for Linux and Mac.}
15
15
  s.email = %q{dreamcat4@gmail.com}
@@ -29,10 +29,8 @@ Gem::Specification.new do |s|
29
29
  "Rakefile",
30
30
  "VERSION",
31
31
  "bin/plist4r",
32
- "ext/osx_plist/Makefile",
33
32
  "ext/osx_plist/extconf.rb",
34
33
  "ext/osx_plist/plist.c",
35
- "ext/osx_plist/plist.o",
36
34
  "features/plist4r.feature",
37
35
  "features/step_definitions/plist4r_steps.rb",
38
36
  "features/support/env.rb",
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 0
8
7
  - 1
9
- version: 1.0.1
8
+ - 0
9
+ version: 1.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - dreamcat4
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-20 00:00:00 +01:00
17
+ date: 2010-07-21 00:00:00 +01:00
18
18
  default_executable: plist4r
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -110,10 +110,8 @@ files:
110
110
  - Rakefile
111
111
  - VERSION
112
112
  - bin/plist4r
113
- - ext/osx_plist/Makefile
114
113
  - ext/osx_plist/extconf.rb
115
114
  - ext/osx_plist/plist.c
116
- - ext/osx_plist/plist.o
117
115
  - features/plist4r.feature
118
116
  - features/step_definitions/plist4r_steps.rb
119
117
  - features/support/env.rb
@@ -1,157 +0,0 @@
1
-
2
- SHELL = /bin/sh
3
-
4
- #### Start of system configuration section. ####
5
-
6
- srcdir = .
7
- topdir = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0
8
- hdrdir = $(topdir)
9
- VPATH = $(srcdir):$(topdir):$(hdrdir)
10
- exec_prefix = $(prefix)
11
- prefix = $(DESTDIR)/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr
12
- sharedstatedir = $(prefix)/com
13
- mandir = $(DESTDIR)/usr/share/man
14
- psdir = $(docdir)
15
- oldincludedir = $(DESTDIR)/usr/include
16
- localedir = $(datarootdir)/locale
17
- bindir = $(exec_prefix)/bin
18
- libexecdir = $(exec_prefix)/libexec
19
- sitedir = $(DESTDIR)/Library/Ruby/Site
20
- htmldir = $(docdir)
21
- vendorarchdir = $(vendorlibdir)/$(sitearch)
22
- includedir = $(prefix)/include
23
- infodir = $(DESTDIR)/usr/share/info
24
- vendorlibdir = $(vendordir)/$(ruby_version)
25
- sysconfdir = $(prefix)/etc
26
- libdir = $(exec_prefix)/lib
27
- sbindir = $(exec_prefix)/sbin
28
- rubylibdir = $(libdir)/ruby/$(ruby_version)
29
- docdir = $(datarootdir)/doc/$(PACKAGE)
30
- dvidir = $(docdir)
31
- vendordir = $(libdir)/ruby/vendor_ruby
32
- datarootdir = $(prefix)/share
33
- pdfdir = $(docdir)
34
- archdir = $(rubylibdir)/$(arch)
35
- sitearchdir = $(sitelibdir)/$(sitearch)
36
- datadir = $(datarootdir)
37
- localstatedir = $(prefix)/var
38
- sitelibdir = $(sitedir)/$(ruby_version)
39
-
40
- CC = gcc
41
- LIBRUBY = $(LIBRUBY_SO)
42
- LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
43
- LIBRUBYARG_SHARED =
44
- LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)
45
-
46
- RUBY_EXTCONF_H =
47
- CFLAGS = -fno-common -arch i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common $(cflags)
48
- INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
49
- DEFS =
50
- CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags)
51
- CXXFLAGS = $(CFLAGS)
52
- ldflags = -L. -arch i386 -arch x86_64 -framework CoreFoundation -undefined suppress -flat_namespace
53
- dldflags =
54
- archflag =
55
- DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
56
- LDSHARED = cc -arch i386 -arch x86_64 -pipe -bundle -undefined dynamic_lookup
57
- AR = ar
58
- EXEEXT =
59
-
60
- RUBY_INSTALL_NAME = ruby
61
- RUBY_SO_NAME = ruby
62
- arch = universal-darwin10.0
63
- sitearch = universal-darwin10.0
64
- ruby_version = 1.8
65
- ruby = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
66
- RUBY = $(ruby)
67
- RM = rm -f
68
- MAKEDIRS = mkdir -p
69
- INSTALL = /usr/bin/install -c
70
- INSTALL_PROG = $(INSTALL) -m 0755
71
- INSTALL_DATA = $(INSTALL) -m 644
72
- COPY = cp
73
-
74
- #### End of system configuration section. ####
75
-
76
- preload =
77
-
78
- libpath = . $(libdir)
79
- LIBPATH = -L. -L$(libdir)
80
- DEFFILE =
81
-
82
- CLEANFILES = mkmf.log
83
- DISTCLEANFILES =
84
-
85
- extout =
86
- extout_prefix =
87
- target_prefix = /plist4r/backend/osx_plist/ext
88
- LOCAL_LIBS =
89
- LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl
90
- SRCS = plist.c
91
- OBJS = plist.o
92
- TARGET = osx_plist
93
- DLLIB = $(TARGET).bundle
94
- EXTSTATIC =
95
- STATIC_LIB =
96
-
97
- BINDIR = $(bindir)
98
- RUBYCOMMONDIR = $(sitedir)$(target_prefix)
99
- RUBYLIBDIR = $(sitelibdir)$(target_prefix)
100
- RUBYARCHDIR = $(sitearchdir)$(target_prefix)
101
-
102
- TARGET_SO = $(DLLIB)
103
- CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
104
- CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
105
-
106
- all: $(DLLIB)
107
- static: $(STATIC_LIB)
108
-
109
- clean:
110
- @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
111
-
112
- distclean: clean
113
- @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
114
- @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
115
-
116
- realclean: distclean
117
- install: install-so install-rb
118
-
119
- install-so: $(RUBYARCHDIR)
120
- install-so: $(RUBYARCHDIR)/$(DLLIB)
121
- $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
122
- $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
123
- install-rb: pre-install-rb install-rb-default
124
- install-rb-default: pre-install-rb-default
125
- pre-install-rb: Makefile
126
- pre-install-rb-default: Makefile
127
- $(RUBYARCHDIR):
128
- $(MAKEDIRS) $@
129
-
130
- site-install: site-install-so site-install-rb
131
- site-install-so: install-so
132
- site-install-rb: install-rb
133
-
134
- .SUFFIXES: .c .m .cc .cxx .cpp .C .o
135
-
136
- .cc.o:
137
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
138
-
139
- .cxx.o:
140
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
141
-
142
- .cpp.o:
143
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
144
-
145
- .C.o:
146
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
147
-
148
- .c.o:
149
- $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
150
-
151
- $(DLLIB): $(OBJS) Makefile
152
- @-$(RM) $@
153
- $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
154
-
155
-
156
-
157
- $(OBJS): ruby.h defines.h
Binary file