public
Rubygem
Description: Ruby osx/plist extension for reading/writing property lists
Clone URL: git://github.com/kballard/osx-plist.git
Search Repo:
Update osx/plist library to use OSX::PropertyList and 
OSX::PropertyListError
PropertyList module kept for backwards compatibility, produces warning on 
first method call, forwards all calls to OSX::PropertyList
PropertyListError is now gone for good (I can't think of a good way to 
hook into const_missing for this)
Note that internal usage of PropertyList now needs to be updated to use 
OSX::PropertyList
kballard (author)
Sat Jun 09 01:51:08 -0700 2007
commit  1045625fa4581907cd6e755958af50ed481a946f
tree    6e898e7741592508921fbb41691ae2055e487ca6
parent  f19cf37e59fe2eb1c452ae05b0cb28984bf64eb8
...
8
9
10
11
 
12
13
14
15
...
67
68
69
 
70
 
71
72
73
...
112
113
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
116
117
118
...
556
557
558
559
 
 
 
 
560
561
562
563
564
565
 
566
567
568
...
8
9
10
 
11
12
13
14
15
...
67
68
69
70
71
72
73
74
75
...
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
...
575
576
577
 
578
579
580
581
582
583
584
585
586
 
587
588
589
590
0
@@ -8,7 +8,7 @@
0
  * Copyright © 2005, Kevin Ballard
0
  *
0
  * Usage:
0
- * This extension provides a module named PropertyList
0
+ * This extension provides a module named OSX::PropertyList
0
  * This module has two methods:
0
  *
0
  * PropertyList::load(obj, format = false)
0
0
@@ -67,7 +67,9 @@
0
   } while (0)
0
 #endif
0
 
0
+static VALUE mOSX;
0
 static VALUE mPlist;
0
+static VALUE mPlistDeprecated;
0
 static VALUE timeEpoch;
0
 static VALUE ePropertyListError;
0
 
0
@@ -112,6 +114,23 @@
0
 }
0
 
0
 /* call-seq:
0
+ * PropertyList.method_missing(symbol, [args]) -> result
0
+ *
0
+ * Forwards all method calls to the OSX::PropertyList class after
0
+ * outputting a warning.
0
+ */
0
+VALUE plist_deprecated_method_missing(int argc, VALUE *argv, VALUE self) {
0
+ static bool shownWarning = false;
0
+ if (!shownWarning) {
0
+ fprintf(stderr, "Warning: PropertyList is deprecated. Use OSX::PropertyList instead.\n");
0
+ shownWarning = true;
0
+ }
0
+ VALUE symbol = *argv++; argc--;
0
+ Check_Type(symbol, T_SYMBOL);
0
+ return rb_funcall3(mPlist, SYM2ID(symbol), argc, argv);
0
+}
0
+
0
+/* call-seq:
0
  * PropertyList.load(obj) -> object
0
  * PropertyList.load(obj, format) -> [object, format]
0
  *
0
0
@@ -556,13 +575,16 @@
0
  * Only works when CoreFoundation is available.
0
  */
0
 void Init_plist() {
0
- mPlist = rb_define_module("PropertyList");
0
+ mPlistDeprecated = rb_define_module("PropertyList");
0
+ rb_define_module_function(mPlistDeprecated,"method_missing", plist_deprecated_method_missing, -1);
0
+ mOSX = rb_define_module("OSX");
0
+ mPlist = rb_define_module_under(mOSX, "PropertyList");
0
   rb_define_module_function(mPlist, "load", plist_load, -1);
0
   rb_define_module_function(mPlist, "dump", plist_dump, -1);
0
   rb_define_method(rb_cObject, "to_plist", obj_to_plist, -1);
0
   rb_define_method(rb_cString, "blob?", str_blob, 0);
0
   rb_define_method(rb_cString, "blob=", str_setBlob, 1);
0
- ePropertyListError = rb_define_class("PropertyListError", rb_eStandardError);
0
+ ePropertyListError = rb_define_class_under(mOSX, "PropertyListError", rb_eStandardError);
0
   id_gm = rb_intern("gm");
0
   timeEpoch = rb_funcall(rb_cTime, id_gm, 1, INT2FIX(2001));
0
   rb_define_const(mPlist, "EPOCH", timeEpoch);
...
3
4
5
6
7
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
42
43
 
 
44
45
 
46
47
48
49
50
51
52
 
 
 
 
 
 
53
54
55
56
57
58
59
60
 
 
 
 
 
 
 
61
62
63
64
65
66
67
 
 
 
 
 
 
68
69
70
71
72
 
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
97
...
3
4
5
 
 
 
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
 
53
54
55
 
56
57
 
 
 
 
 
 
58
59
60
61
62
63
64
 
 
 
 
 
 
 
65
66
67
68
69
70
71
72
 
 
 
 
 
 
73
74
75
76
77
78
79
80
81
82
 
83
84
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
0
@@ -3,96 +3,107 @@
0
 require 'test/unit'
0
 
0
 class TestPlist < Test::Unit::TestCase
0
- def test_string
0
- plist = PropertyList.load("{foo = bar; }")
0
- assert_equal( { "foo" => "bar" }, plist )
0
+ def test_deprecation_warning
0
+ savederr = STDERR.clone
0
+ rd, wr = IO.pipe
0
+ STDERR.reopen(wr)
0
+ plist = PropertyList.load("{foo = bar; }")
0
+ plist, format = PropertyList.load("{foo = bar; }", true)
0
+ STDERR.reopen(savederr)
0
+ wr.close
0
+ assert_equal( "Warning: PropertyList is deprecated. Use OSX::PropertyList instead.\n", rd.read)
0
+ end
0
+
0
+ def test_string
0
+ plist = OSX::PropertyList.load("{foo = bar; }")
0
+ assert_equal( { "foo" => "bar" }, plist )
0
 
0
- plist, format = PropertyList.load("{foo = bar; }", true)
0
- assert_equal( { "foo" => "bar" }, plist )
0
- assert_equal( :openstep, format )
0
-
0
- # make sure sources < 6 characters work
0
- plist = PropertyList.load("foo")
0
- assert_equal( "foo", plist )
0
-
0
- # make sure it works with format too
0
- plist, format = PropertyList.load("foo", true)
0
- assert_equal( "foo", plist )
0
- assert_equal( :openstep, format )
0
-
0
- assert_raise(PropertyListError) { PropertyList.load("") }
0
- end
0
+ plist, format = OSX::PropertyList.load("{foo = bar; }", true)
0
+ assert_equal( { "foo" => "bar" }, plist )
0
+ assert_equal( :openstep, format )
0
+
0
+ # make sure sources < 6 characters work
0
+ plist = OSX::PropertyList.load("foo")
0
+ assert_equal( "foo", plist )
0
+
0
+ # make sure it works with format too
0
+ plist, format = OSX::PropertyList.load("foo", true)
0
+ assert_equal( "foo", plist )
0
+ assert_equal( :openstep, format )
0
+
0
+ assert_raise(OSX::PropertyListError) { OSX::PropertyList.load("") }
0
+ end
0
 
0
- def setup_hash
0
- time = Time.gm(2005, 4, 28, 6, 32, 56)
0
- random = "\x23\x45\x67\x89"
0
- random.blob = true
0
- {
0
- "string!" => "indeedy",
0
- "bar" => [ 1, 2, 3 ],
0
- "foo" => {
0
- "correct?" => true,
0
- "pi" => 3.14159265,
0
- "random" => random,
0
- "today" => time,
0
- }
0
- }
0
- end
0
+ def setup_hash
0
+ time = Time.gm(2005, 4, 28, 6, 32, 56)
0
+ random = "\x23\x45\x67\x89"
0
+ random.blob = true
0
+ {
0
+ "string!" => "indeedy",
0
+ "bar" => [ 1, 2, 3 ],
0
+ "foo" => {
0
+ "correct?" => true,
0
+ "pi" => 3.14159265,
0
+ "random" => random,
0
+ "today" => time,
0
+ }
0
+ }
0
+ end
0
 
0
- def test_io
0
- plist, format = PropertyList.load(DATA, true)
0
+ def test_io
0
+ plist, format = OSX::PropertyList.load(DATA, true)
0
 
0
- hash = setup_hash
0
+ hash = setup_hash
0
 
0
- assert_equal(hash, plist)
0
- assert_equal(true, plist['foo']['random'].blob?)
0
- assert_equal(false, plist['string!'].blob?)
0
-
0
- assert_equal(:xml1, format)
0
- end
0
+ assert_equal(hash, plist)
0
+ assert_equal(true, plist['foo']['random'].blob?)
0
+ assert_equal(false, plist['string!'].blob?)
0
+
0
+ assert_equal(:xml1, format)
0
+ end
0
 
0
- def test_dump
0
- str = StringIO.new("", "w")
0
- hash = setup_hash
0
- PropertyList.dump(str, hash)
0
- hash2 = PropertyList.load(str.string)
0
- assert_equal(hash, hash2)
0
- end
0
+ def test_dump
0
+ str = StringIO.new("", "w")
0
+ hash = setup_hash
0
+ OSX::PropertyList.dump(str, hash)
0
+ hash2 = OSX::PropertyList.load(str.string)
0
+ assert_equal(hash, hash2)
0
+ end
0
 
0
- def test_to_plist
0
- assert_raise(PropertyListError) { "foo".to_plist(:openstep) }
0
- assert_equal("foo", PropertyList.load("foo".to_plist))
0
- hash = setup_hash()
0
- assert_equal(hash, PropertyList.load(hash.to_plist))
0
- end
0
+ def test_to_plist
0
+ assert_raise(OSX::PropertyListError) { "foo".to_plist(:openstep) }
0
+ assert_equal("foo", OSX::PropertyList.load("foo".to_plist))
0
+ hash = setup_hash()
0
+ assert_equal(hash, OSX::PropertyList.load(hash.to_plist))
0
+ end
0
 end
0
 
0
 __END__
0
 <?xml version="1.0" encoding="UTF-8"?>
0
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
0
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/OSX::PropertyList-1.0.dtd">
0
 <plist version="1.0">
0
 <dict>
0
- <key>string!</key>
0
- <string>indeedy</string>
0
- <key>bar</key>
0
- <array>
0
- <integer>1</integer>
0
- <integer>2</integer>
0
- <integer>3</integer>
0
- </array>
0
- <key>foo</key>
0
- <dict>
0
- <key>correct?</key>
0
- <true/>
0
- <key>pi</key>
0
- <real>3.14159265</real>
0
- <key>random</key>
0
- <data>
0
- I0VniQ==
0
- </data>
0
- <key>today</key>
0
- <date>2005-04-28T06:32:56Z</date>
0
- </dict>
0
+ <key>string!</key>
0
+ <string>indeedy</string>
0
+ <key>bar</key>
0
+ <array>
0
+ <integer>1</integer>
0
+ <integer>2</integer>
0
+ <integer>3</integer>
0
+ </array>
0
+ <key>foo</key>
0
+ <dict>
0
+ <key>correct?</key>
0
+ <true/>
0
+ <key>pi</key>
0
+ <real>3.14159265</real>
0
+ <key>random</key>
0
+ <data>
0
+ I0VniQ==
0
+ </data>
0
+ <key>today</key>
0
+ <date>2005-04-28T06:32:56Z</date>
0
+ </dict>
0
 </dict>
0
 </plist>

Comments

    No one has commented yet.