Skip to content

Commit d3055e9

Browse files
committed
[PlistHelper] Import build of old C ext for Ruby 1.8.7 only.
1 parent efd4694 commit d3055e9

File tree

5 files changed

+42
-32
lines changed

5 files changed

+42
-32
lines changed
42 KB
Binary file not shown.

lib/xcodeproj.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ def message
2020
autoload :Workspace, 'xcodeproj/workspace'
2121
autoload :XCScheme, 'xcodeproj/scheme'
2222
autoload :XcodebuildHelper, 'xcodeproj/xcodebuild_helper'
23-
24-
# TODO: Delete me (compatibility with CocoaPods 0.33.1)
25-
def self.read_plist(path)
26-
PlistHelper.read(path)
27-
end
28-
29-
def self.write_plist(hash, path)
30-
PlistHelper.write(hash, path)
31-
end
3223
end
24+
25+
require 'xcodeproj/ext'

lib/xcodeproj/ext.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
begin
22
require 'xcodeproj/plist_helper'
33
rescue LoadError
4-
raise 'TODO: Load Ruby 1.8.7 C ext?'
4+
require 'rbconfig'
5+
if RUBY_VERSION == '1.8.7' && RbConfig::CONFIG['prefix'] =~ %r{^/System/Library/Frameworks/Ruby.framework/}
6+
$:.unshift(File.expand_path('../../../ext', __FILE__))
7+
require 'xcodeproj/xcodeproj_ext-1.8.7'
8+
else
9+
raise 'The xcodeproj gem is only supported on Ruby versions that include' \
10+
'the Fiddle API or with Ruby 1.8.7 that came with OS X 10.8.x.'
11+
end
512
end

lib/xcodeproj/plist_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
require 'fiddle'
22

33
module Xcodeproj
4+
# TODO: Delete me (compatibility with Ruby 1.8.7 C ext bundle)
5+
def self.read_plist(path)
6+
PlistHelper.read(path)
7+
end
8+
9+
# TODO: Delete me (compatibility with Ruby 1.8.7 C ext bundle)
10+
def self.write_plist(hash, path)
11+
PlistHelper.write(hash, path)
12+
end
13+
414
# Provides support for loading and serializing property list files.
515
#
616
module PlistHelper

spec/plist_helper_spec.rb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ module ProjectSpecs
1414

1515
it 'writes an XML plist file' do
1616
hash = { 'archiveVersion' => '1.0' }
17-
Xcodeproj::PlistHelper.write(hash, @plist)
18-
result = Xcodeproj::PlistHelper.read(@plist)
17+
Xcodeproj.write_plist(hash, @plist)
18+
result = Xcodeproj.read_plist(@plist)
1919
result.should == hash
2020
@plist.read.should.include('?xml')
2121
end
2222

2323
it 'reads an ASCII plist file' do
2424
dir = 'Sample Project/Cocoa Application.xcodeproj/'
2525
path = fixture_path(dir + 'project.pbxproj')
26-
result = Xcodeproj::PlistHelper.read(path)
26+
result = Xcodeproj.read_plist(path)
2727
result.keys.should.include?('archiveVersion')
2828
end
2929

@@ -42,7 +42,7 @@ module ProjectSpecs
4242
# rubocop:enable Style/Tab
4343

4444
hash = { 'archiveVersion' => '1.0' }
45-
Xcodeproj::PlistHelper.write(hash, @plist)
45+
Xcodeproj.write_plist(hash, @plist)
4646
@plist.read.should == output
4747
end
4848

@@ -55,34 +55,34 @@ module ProjectSpecs
5555

5656
it 'coerces the given path object to a string path' do
5757
# @plist is a Pathname
58-
Xcodeproj::PlistHelper.write({}, @plist)
59-
Xcodeproj::PlistHelper.read(@plist).should == {}
58+
Xcodeproj.write_plist({}, @plist)
59+
Xcodeproj.read_plist(@plist).should == {}
6060
end
6161

6262
it "raises when the given path can't be coerced into a string path" do
63-
lambda { Xcodeproj::PlistHelper.write({}, Object.new) }.should.raise TypeError
63+
lambda { Xcodeproj.write_plist({}, Object.new) }.should.raise TypeError
6464
end
6565

6666
it "raises if the given path doesn't exist" do
67-
lambda { Xcodeproj::PlistHelper.read('doesnotexist') }.should.raise ArgumentError
67+
lambda { Xcodeproj.read_plist('doesnotexist') }.should.raise ArgumentError
6868
end
6969

7070
it 'coerces the given hash to a Hash' do
7171
o = Object.new
7272
def o.to_hash
7373
{ 'from' => 'object' }
7474
end
75-
Xcodeproj::PlistHelper.write(o, @plist)
76-
Xcodeproj::PlistHelper.read(@plist).should == { 'from' => 'object' }
75+
Xcodeproj.write_plist(o, @plist)
76+
Xcodeproj.read_plist(@plist).should == { 'from' => 'object' }
7777
end
7878

7979
it "raises when given a hash that can't be coerced to a Hash" do
80-
lambda { Xcodeproj::PlistHelper.write(Object.new, @plist) }.should.raise TypeError
80+
lambda { Xcodeproj.write_plist(Object.new, @plist) }.should.raise TypeError
8181
end
8282

8383
it 'coerces keys to strings' do
84-
Xcodeproj::PlistHelper.write({ 1 => '1', :symbol => 'symbol' }, @plist)
85-
Xcodeproj::PlistHelper.read(@plist).should == { '1' => '1', 'symbol' => 'symbol' }
84+
Xcodeproj.write_plist({ 1 => '1', :symbol => 'symbol' }, @plist)
85+
Xcodeproj.read_plist(@plist).should == { '1' => '1', 'symbol' => 'symbol' }
8686
end
8787

8888
it 'allows hashes, strings, booleans, and arrays of hashes and strings as values' do
@@ -93,19 +93,19 @@ def o.to_hash
9393
'false_bool' => false,
9494
'array' => ['string in an array', { 'a hash' => 'in an array' }],
9595
}
96-
Xcodeproj::PlistHelper.write(hash, @plist)
97-
Xcodeproj::PlistHelper.read(@plist).should == hash
96+
Xcodeproj.write_plist(hash, @plist)
97+
Xcodeproj.read_plist(@plist).should == hash
9898
end
9999

100100
it 'coerces values to strings if it is a disallowed type' do
101-
Xcodeproj::PlistHelper.write({ '1' => 1, 'symbol' => :symbol }, @plist)
102-
Xcodeproj::PlistHelper.read(@plist).should == { '1' => '1', 'symbol' => 'symbol' }
101+
Xcodeproj.write_plist({ '1' => 1, 'symbol' => :symbol }, @plist)
102+
Xcodeproj.read_plist(@plist).should == { '1' => '1', 'symbol' => 'symbol' }
103103
end
104104

105105
it 'handles unicode characters in paths and strings' do
106106
plist = @plist.to_s + 'øµ'
107-
Xcodeproj::PlistHelper.write({ 'café' => 'før yoµ' }, plist)
108-
Xcodeproj::PlistHelper.read(plist).should == { 'café' => 'før yoµ' }
107+
Xcodeproj.write_plist({ 'café' => 'før yoµ' }, plist)
108+
Xcodeproj.read_plist(plist).should == { 'café' => 'før yoµ' }
109109
end
110110

111111
it 'raises if a plist contains any other object type as value than string, dictionary, and array' do
@@ -121,7 +121,7 @@ def o.to_hash
121121
</plist>
122122
EOS
123123
end
124-
lambda { Xcodeproj::PlistHelper.read(@plist) }.should.raise TypeError
124+
lambda { Xcodeproj.read_plist(@plist) }.should.raise TypeError
125125
end
126126

127127
it 'raises if a plist array value contains any other object type than string, or dictionary' do
@@ -139,12 +139,12 @@ def o.to_hash
139139
</plist>
140140
EOS
141141
end
142-
lambda { Xcodeproj::PlistHelper.read(@plist) }.should.raise TypeError
142+
lambda { Xcodeproj.read_plist(@plist) }.should.raise TypeError
143143
end
144144

145145
it 'raises if for whatever reason the value could not be converted to a CFTypeRef' do
146146
lambda do
147-
Xcodeproj::PlistHelper.write({ 'invalid' => "\xCA" }, @plist)
147+
Xcodeproj.write_plist({ 'invalid' => "\xCA" }, @plist)
148148
end.should.raise TypeError
149149
end
150150

0 commit comments

Comments
 (0)