rubycf 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +10 -14
- data/lib/plist.h +3 -2
- data/lib/rubycf.c +36 -1
- data/lib/rubycf_extensions.rb +8 -11
- metadata +3 -3
data/README
CHANGED
@@ -1,20 +1,16 @@
|
|
1
|
-
Ruby extension for dealing with CoreFoundation types. Mostly designed for
|
1
|
+
Ruby extension for dealing with CoreFoundation types. Mostly designed for reading/writing binary and xml plists.
|
2
2
|
|
3
|
-
See
|
3
|
+
See RubyCF::PList for available methods.
|
4
4
|
|
5
|
-
|
5
|
+
== Examples
|
6
|
+
See the unit tests for examples.
|
6
7
|
|
7
|
-
About CFData
|
8
|
+
== About CFData
|
8
9
|
Since Ruby doesn't treat strings any differently from raw data and CoreFoundation does, there needed to be a way to specify if a string is a string or if it's just data. For this purpose, I've created the class RubyCF::Data, which is just a container for a ruby string. When a RubyCF::Data object is passed into the plist encoder, it will encode the data as CFData. Likewise, when a CFData object is encountered while decoding a plist, a RubyCF::Data object will be created.
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
- rubyland convenience methods
|
11
|
+
== About CFLite
|
12
|
+
To get this to work outside of the OS X, you need to compile lib/CoreFoundation and link against it when building the gem. This is build into extconf.rb, but you may need to modify it if it can't find the path to your library.
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
Building CFLite:
|
19
|
-
http://cafeine.crulrg.ulaval.ca/users/dccote/weblog/0514e/CoreFoundation_Lite_on_Linux.html
|
20
|
-
http://developer.apple.com/opensource/cflite.html
|
14
|
+
See the following for information on building CFLite under Linux.
|
15
|
+
* http://cafeine.crulrg.ulaval.ca/users/dccote/weblog/0514e/CoreFoundation_Lite_on_Linux.html
|
16
|
+
* http://developer.apple.com/opensource/cflite.html
|
data/lib/plist.h
CHANGED
@@ -3,8 +3,9 @@
|
|
3
3
|
|
4
4
|
RUBY_EXTERN VALUE rb_cCFData;
|
5
5
|
|
6
|
-
|
7
|
-
VALUE
|
6
|
+
// Moved these declarations to rubycf.c so rdoc can find them (lame)
|
7
|
+
// VALUE rbcf_plist_parse(VALUE self, VALUE data);
|
8
|
+
// VALUE rbcf_plist_encode(int argc, VALUE *argv, VALUE self);
|
8
9
|
|
9
10
|
VALUE rbcf_plist_convert_to_ruby(CFPropertyListRef plist);
|
10
11
|
CFPropertyListRef rbcf_plist_convert_to_cf(VALUE structure);
|
data/lib/rubycf.c
CHANGED
@@ -14,12 +14,47 @@
|
|
14
14
|
static VALUE rb_mRubyCF;
|
15
15
|
static VALUE rb_cPlist;
|
16
16
|
|
17
|
+
/*
|
18
|
+
* call-seq:
|
19
|
+
* parse(string) -> Object
|
20
|
+
*
|
21
|
+
* Parse a string containing the property list data. Any of the
|
22
|
+
* property list formats will work, including the deprecated
|
23
|
+
* OpenStep format.
|
24
|
+
*/
|
25
|
+
VALUE rbcf_plist_parse(VALUE self, VALUE data);
|
26
|
+
|
27
|
+
/*
|
28
|
+
* call-seq:
|
29
|
+
* encode(Object) -> string
|
30
|
+
* encode(Object, :xml) -> string
|
31
|
+
*
|
32
|
+
* Encode a compatible object into a property list. The default
|
33
|
+
* format is binary, but you can specify :xml to get the xml format
|
34
|
+
* instead. The OpenStep format is deprecated by CoreFoundation
|
35
|
+
* and is not available in RubyCF.
|
36
|
+
*
|
37
|
+
* Compatible formats are:
|
38
|
+
* * RubyCF::Data
|
39
|
+
* * Hash
|
40
|
+
* * Array
|
41
|
+
* * Number
|
42
|
+
* * Time
|
43
|
+
* * Boolean
|
44
|
+
* * anything that responds to to_hash
|
45
|
+
*/
|
46
|
+
VALUE rbcf_plist_encode(int argc, VALUE *argv, VALUE self);
|
47
|
+
|
17
48
|
void Init_rubycf (void)
|
18
49
|
{
|
19
50
|
// Add the initialization code of your module here.
|
20
51
|
rb_mRubyCF = rb_define_module("RubyCF");
|
21
|
-
|
52
|
+
|
53
|
+
/*
|
54
|
+
* Methods for encoding and decoding property lists
|
55
|
+
*/
|
22
56
|
rb_cPlist = rb_define_class_under(rb_mRubyCF, "PList", rb_cObject);
|
57
|
+
|
23
58
|
rb_define_module_function(rb_cPlist, "parse", rbcf_plist_parse, 1);
|
24
59
|
rb_define_module_function(rb_cPlist, "encode", rbcf_plist_encode, -1);
|
25
60
|
|
data/lib/rubycf_extensions.rb
CHANGED
@@ -1,26 +1,30 @@
|
|
1
1
|
# Extensions to the build in C functions
|
2
2
|
|
3
3
|
module RubyCF
|
4
|
+
|
4
5
|
class PList
|
5
6
|
class << self
|
6
7
|
alias decode parse
|
7
8
|
end
|
8
9
|
|
10
|
+
# Parse a plist from a file path or handle
|
9
11
|
def self.parse_file file
|
10
12
|
self.parse(file.is_a?(File) ? file.read : File.read(file))
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
16
|
# CF handles raw data different from strings. Ruby treats them the same.
|
15
|
-
#
|
17
|
+
# Use RubyCF::Data objects to tell the plist encoder to treat the objects
|
16
18
|
# as data.
|
17
19
|
class Data
|
18
20
|
attr_reader :data
|
19
21
|
|
22
|
+
# Create a RubyCF::Data object from a file path or handle
|
20
23
|
def self.from_file file
|
21
24
|
Data.new(file.is_a?(File) ? file.read : File.read(file))
|
22
25
|
end
|
23
26
|
|
27
|
+
# Create a RubyCF::Data object from a string
|
24
28
|
def initialize string
|
25
29
|
self.data = string
|
26
30
|
end
|
@@ -45,15 +49,8 @@ module RubyCF
|
|
45
49
|
end
|
46
50
|
|
47
51
|
class Object
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
return RubyCF::PList.encode(self, type) #if self.is_a? klass
|
52
|
-
# end
|
53
|
-
#
|
54
|
-
# if self.resond_to? :to_hash
|
55
|
-
# elsif self.resond_to? :to_a
|
56
|
-
# elsif self.resond_to?
|
57
|
-
#
|
52
|
+
# Shorthand for RubyCF::PList.encode(object, format)
|
53
|
+
def to_plist(format = :binary)
|
54
|
+
RubyCF::PList.encode(self, format)
|
58
55
|
end
|
59
56
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubycf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Grijalva
|
@@ -40,7 +40,7 @@ files:
|
|
40
40
|
- lib/rubycf_extensions.rb
|
41
41
|
- README
|
42
42
|
has_rdoc: true
|
43
|
-
homepage: http://
|
43
|
+
homepage: http://github.com/ngmoco/rubycf/
|
44
44
|
licenses: []
|
45
45
|
|
46
46
|
post_install_message:
|
@@ -66,6 +66,6 @@ rubyforge_project:
|
|
66
66
|
rubygems_version: 1.3.5
|
67
67
|
signing_key:
|
68
68
|
specification_version: 3
|
69
|
-
summary:
|
69
|
+
summary: Ruby extension for dealing with CoreFoundation types. Mostly designed for reading and writing xml and binary property lists.
|
70
70
|
test_files: []
|
71
71
|
|