zerg_xcode 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/zerg_xcode/objects/pbx_group.rb +64 -22
- data/lib/zerg_xcode/objects/pbx_project.rb +0 -4
- data/spec/objects/pbx_group_spec.rb +134 -0
- data/test/objects/pbx_project_test.rb +0 -7
- data/zerg_xcode.gemspec +3 -3
- metadata +14 -14
- data/test/objects/pbx_group_test.rb +0 -44
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
@@ -10,34 +10,76 @@ module ZergXcode::Objects
|
|
10
10
|
|
11
11
|
# A group of files (shown as a folder) in an Xcode project.
|
12
12
|
class PBXGroup < ZergXcode::XcodeObject
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
|
14
|
+
# call-seq:
|
15
|
+
# mkdir(name) ⇒ aChild
|
16
|
+
#
|
17
|
+
# Creates a child group with name _name_. Raises Errno::EEXIST if a child
|
18
|
+
# with that name already exists.
|
19
|
+
def mkdir name
|
20
|
+
raise Errno::ENOTNAM if name =~ /\//
|
21
|
+
raise Errno::EEXIST if exists? name
|
22
|
+
group = ZergXcode::Objects::PBXGroup.new 'name' => name,
|
23
|
+
'path' => name,
|
24
|
+
'children' => [],
|
25
|
+
'sourceTree' => '<group>'
|
26
|
+
self.children << group
|
27
|
+
group
|
28
|
+
end
|
29
|
+
|
30
|
+
# call-seq:
|
31
|
+
# mkdir_f(name) ⇒ aChild
|
32
|
+
#
|
33
|
+
# If a child with name _name_ already exists, that child is returned;
|
34
|
+
# otherwise, a new child group is created and returned.
|
35
|
+
def mkdir_f name
|
36
|
+
child_with_name(name) || mkdir(name)
|
37
|
+
end
|
38
|
+
|
39
|
+
# call-seq:
|
40
|
+
# mkdir_p(path) ⇒ aChild
|
41
|
+
#
|
42
|
+
# If a child with path _path_ exists, that child is returned; otherwise,
|
43
|
+
# groups are created to make the path exist and the deepest group is
|
44
|
+
# returned.
|
45
|
+
def mkdir_p path
|
46
|
+
path_elements(path).inject(self) do |group, path_element|
|
47
|
+
group.mkdir_f path_element
|
22
48
|
end
|
23
|
-
return nil
|
24
49
|
end
|
25
|
-
|
50
|
+
|
51
|
+
# An array of all immediate children of this node
|
52
|
+
attr_reader :children
|
26
53
|
def children
|
27
54
|
self['children']
|
28
55
|
end
|
29
56
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
'children' => [],
|
36
|
-
'sourceTree' => source_tree
|
37
|
-
self.children << group
|
57
|
+
# If a child exists at the specified path (which may contain slashes), that
|
58
|
+
# child is returned. Otherwise, nil is returned.
|
59
|
+
def child_with_path path
|
60
|
+
path_elements(path).inject(self) do |group, path_element|
|
61
|
+
group.child_with_name(path_element) if group
|
38
62
|
end
|
39
|
-
group
|
40
63
|
end
|
41
|
-
|
64
|
+
alias_method :exist?, :child_with_path
|
65
|
+
alias_method :exists?, :child_with_path
|
66
|
+
|
67
|
+
# If this group has an _immediate_ child with the specified name, it is
|
68
|
+
# returned; otherwise, nil is returned.
|
69
|
+
def child_with_name name
|
70
|
+
children.detect {|child| child.xref_name == name}
|
71
|
+
end
|
72
|
+
|
73
|
+
# :nodoc:
|
74
|
+
def to_s
|
75
|
+
"PBXGroup<#{xref_name}>"
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
def path_elements path
|
80
|
+
path.split('/')
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
42
84
|
|
43
|
-
end
|
85
|
+
end
|
@@ -43,10 +43,6 @@ class PBXProject < ZergXcode::XcodeObject
|
|
43
43
|
isa.to_s
|
44
44
|
end
|
45
45
|
|
46
|
-
def find_group_named name
|
47
|
-
self["mainGroup"].find_group_named name
|
48
|
-
end
|
49
|
-
|
50
46
|
# Container for the visitor that lists all files in a project.
|
51
47
|
module FileVisitor
|
52
48
|
def self.visit(object, root_path, files)
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'zerg_xcode'
|
2
|
+
|
3
|
+
describe PBXGroup = ZergXcode::Objects::PBXGroup do
|
4
|
+
let(:proj) { ZergXcode.load 'spec/fixtures/project.pbxproj' }
|
5
|
+
let(:main_group) { proj['mainGroup'] }
|
6
|
+
|
7
|
+
context "when the meta data says it should be a pbx group" do
|
8
|
+
subject { main_group }
|
9
|
+
it { should be_a PBXGroup }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#mkdir' do
|
13
|
+
context 'when the group does not already exist' do
|
14
|
+
describe 'the new group' do
|
15
|
+
subject { main_group.mkdir 'New Group' }
|
16
|
+
it { should_not be_nil }
|
17
|
+
it 'should have children' do
|
18
|
+
subject.children.should_not be_nil
|
19
|
+
end
|
20
|
+
it 'should have a "sourceTree" of "<group>"' do
|
21
|
+
subject['sourceTree'].should eq "<group>"
|
22
|
+
end
|
23
|
+
it { should be_found_within main_group }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
context 'when the group already exists' do
|
27
|
+
before {main_group.mkdir 'New Group'}
|
28
|
+
describe 'the invocation' do
|
29
|
+
subject {lambda {main_group.mkdir 'New Group'}}
|
30
|
+
it {should raise_error(Errno::EEXIST)}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
context 'using a group name with a slash' do
|
34
|
+
describe 'the invocation' do
|
35
|
+
subject {lambda {main_group.mkdir 'Foo/Bar'}}
|
36
|
+
it {should raise_error(Errno::ENOTNAM)}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#mkdir_f' do
|
42
|
+
context 'when the group already exists' do
|
43
|
+
let(:the_group) {main_group.mkdir 'Foo'}
|
44
|
+
subject {main_group.mkdir_f 'Foo'}
|
45
|
+
it 'should be that group' do
|
46
|
+
should be(the_group)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
context 'when the group does not exist' do
|
50
|
+
subject {main_group.mkdir_f 'Foo'}
|
51
|
+
it 'should create it' do
|
52
|
+
subject.xref_name.should eq 'Foo'
|
53
|
+
subject.should be_found_within main_group
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#mkdir_p' do
|
59
|
+
before {main_group.mkdir_p 'Foo/Bar'}
|
60
|
+
it 'creates the first part of the path' do
|
61
|
+
main_group.exists?('Foo').should be_true
|
62
|
+
end
|
63
|
+
it 'creates the second part of the path' do
|
64
|
+
main_group.exists?('Foo/Bar').should be_true
|
65
|
+
end
|
66
|
+
context 'when the first part of the path exists' do
|
67
|
+
before do
|
68
|
+
@first = main_group.mkdir 'First'
|
69
|
+
@second = main_group.mkdir_p 'First/Second'
|
70
|
+
end
|
71
|
+
it 'reuses the first part' do
|
72
|
+
@second.should be_found_within @first
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#child_with_path' do
|
78
|
+
context 'with a one-element path' do
|
79
|
+
subject {main_group.exists?('Foo')}
|
80
|
+
context 'when the element does not exist' do
|
81
|
+
it {should be_nil}
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'when the element exists' do
|
85
|
+
let(:foo) {main_group.mkdir 'Foo'}
|
86
|
+
it 'should be that element' do
|
87
|
+
should be(foo)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'with a multiple element path' do
|
93
|
+
subject {main_group.exists?('Foo/Bar/Baz')}
|
94
|
+
context 'when no elements of the path exist' do
|
95
|
+
it {should be_nil}
|
96
|
+
end
|
97
|
+
context 'when part of the path exists' do
|
98
|
+
before {main_group.mkdir('Foo').mkdir('Bar')}
|
99
|
+
it {should be_nil}
|
100
|
+
end
|
101
|
+
context 'when all of the path exists' do
|
102
|
+
let(:last_element) {main_group.mkdir('Foo').mkdir('Bar').mkdir('Baz')}
|
103
|
+
it 'should be the last element of that path' do
|
104
|
+
should be(last_element)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#child_with_name' do
|
111
|
+
subject {main_group.child_with_name 'Foo'}
|
112
|
+
context 'when the child does not exist' do
|
113
|
+
it {should be_nil}
|
114
|
+
end
|
115
|
+
context 'when the child exists' do
|
116
|
+
let(:the_child) {main_group.mkdir 'Foo'}
|
117
|
+
it 'should be that child' do
|
118
|
+
should be(the_child)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
Rspec::Matchers.define :be_found_within do |expected|
|
127
|
+
match do |actual|
|
128
|
+
expected.child_with_name(actual.xref_name).equal? actual
|
129
|
+
end
|
130
|
+
failure_message_for_should do |actual|
|
131
|
+
"expected #{expected.xref_name} to be found within #{actual.xref_name}"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
@@ -81,11 +81,4 @@ class PBXProjectTest < Test::Unit::TestCase
|
|
81
81
|
assert_equal 'PBXProject', project.xref_name
|
82
82
|
end
|
83
83
|
|
84
|
-
def test_find_group_named
|
85
|
-
project = ZergXcode.load('spec/fixtures/project.pbxproj')
|
86
|
-
found_group = project.find_group_named("Classes")
|
87
|
-
assert_not_nil found_group
|
88
|
-
assert_equal PBXGroup, found_group.class
|
89
|
-
assert_equal "Classes", found_group.xref_name
|
90
|
-
end
|
91
84
|
end
|
data/zerg_xcode.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "zerg_xcode"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Victor Costan"]
|
12
|
-
s.date = "2012-01-
|
12
|
+
s.date = "2012-01-12"
|
13
13
|
s.email = "victor@zergling.net"
|
14
14
|
s.executables = ["zerg-xcode"]
|
15
15
|
s.extra_rdoc_files = [
|
@@ -74,13 +74,13 @@ Gem::Specification.new do |s|
|
|
74
74
|
"spec/fixtures/project.pbxproj.compat",
|
75
75
|
"spec/id_generator_spec.rb",
|
76
76
|
"spec/lexer_spec.rb",
|
77
|
+
"spec/objects/pbx_group_spec.rb",
|
77
78
|
"spec/parser_spec.rb",
|
78
79
|
"spec/paths_spec.rb",
|
79
80
|
"spec/shortcuts_spec.rb",
|
80
81
|
"test/objects/pbx_build_file_test.rb",
|
81
82
|
"test/objects/pbx_build_phase_test.rb",
|
82
83
|
"test/objects/pbx_container_item_proxy_test.rb",
|
83
|
-
"test/objects/pbx_group_test.rb",
|
84
84
|
"test/objects/pbx_native_target_test.rb",
|
85
85
|
"test/objects/pbx_project_test.rb",
|
86
86
|
"test/objects/pbx_target_dependency_test.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zerg_xcode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &70192525123100 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70192525123100
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: jeweler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70192525135440 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.6.4
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70192525135440
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rcov
|
38
|
-
requirement: &
|
38
|
+
requirement: &70192525132800 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70192525132800
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70192525144980 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.7.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70192525144980
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: flexmock
|
60
|
-
requirement: &
|
60
|
+
requirement: &70192525142780 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70192525142780
|
69
69
|
description:
|
70
70
|
email: victor@zergling.net
|
71
71
|
executables:
|
@@ -132,13 +132,13 @@ files:
|
|
132
132
|
- spec/fixtures/project.pbxproj.compat
|
133
133
|
- spec/id_generator_spec.rb
|
134
134
|
- spec/lexer_spec.rb
|
135
|
+
- spec/objects/pbx_group_spec.rb
|
135
136
|
- spec/parser_spec.rb
|
136
137
|
- spec/paths_spec.rb
|
137
138
|
- spec/shortcuts_spec.rb
|
138
139
|
- test/objects/pbx_build_file_test.rb
|
139
140
|
- test/objects/pbx_build_phase_test.rb
|
140
141
|
- test/objects/pbx_container_item_proxy_test.rb
|
141
|
-
- test/objects/pbx_group_test.rb
|
142
142
|
- test/objects/pbx_native_target_test.rb
|
143
143
|
- test/objects/pbx_project_test.rb
|
144
144
|
- test/objects/pbx_target_dependency_test.rb
|
@@ -167,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
167
167
|
version: '0'
|
168
168
|
segments:
|
169
169
|
- 0
|
170
|
-
hash:
|
170
|
+
hash: 4530039425077302079
|
171
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
172
|
none: false
|
173
173
|
requirements:
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# Author:: Christopher Garrett
|
2
|
-
# Copyright:: Copyright (C) 2009 Zergling.Net
|
3
|
-
# License:: MIT
|
4
|
-
|
5
|
-
require 'zerg_xcode'
|
6
|
-
require 'test/unit'
|
7
|
-
|
8
|
-
class PBXGroupTest < Test::Unit::TestCase
|
9
|
-
PBXGroup = ZergXcode::Objects::PBXGroup
|
10
|
-
|
11
|
-
def setup
|
12
|
-
@proj = ZergXcode.load 'spec/fixtures/project.pbxproj'
|
13
|
-
@main_group = @proj['mainGroup']
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_instantiation
|
17
|
-
assert_equal PBXGroup, @main_group.class
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_find_group_named
|
21
|
-
found_group = @main_group.find_group_named 'Classes'
|
22
|
-
assert_not_nil found_group
|
23
|
-
assert_equal PBXGroup, found_group.class
|
24
|
-
assert_equal 'Classes', found_group.xref_name
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_create_group
|
28
|
-
assert_nil @main_group.find_group_named('Foo'), 'Found inexistent group Foo'
|
29
|
-
|
30
|
-
created_group = @main_group.create_group 'Foo'
|
31
|
-
assert_not_nil created_group, 'Newly created group Foo'
|
32
|
-
assert_not_nil created_group.children,
|
33
|
-
"Newly created group's children attribute"
|
34
|
-
|
35
|
-
new_group = @main_group.find_group_named 'Foo'
|
36
|
-
assert_not_nil new_group, 'Did not find group Foo after creating it'
|
37
|
-
|
38
|
-
# Should return the existing group if it is already there
|
39
|
-
assert_operator created_group, :equal?, @main_group.create_group('Foo'),
|
40
|
-
"create_group should return an existing group if it's there"
|
41
|
-
|
42
|
-
assert_equal "<group>", new_group["sourceTree"]
|
43
|
-
end
|
44
|
-
end
|