xcodeproject 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
data/lib/xcodeproject/version.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'xcodeproject/node'
|
2
|
+
require 'rexml/document'
|
2
3
|
|
3
4
|
module XcodeProject
|
4
5
|
class XCBuildConfiguration < Node
|
@@ -11,5 +12,64 @@ module XcodeProject
|
|
11
12
|
@name = data['name']
|
12
13
|
@build_settings = data['buildSettings']
|
13
14
|
end
|
15
|
+
|
16
|
+
def version (type = :major)
|
17
|
+
major = read_property('CFBundleShortVersionString')
|
18
|
+
minor = read_property('CFBundleVersion')
|
19
|
+
|
20
|
+
case type
|
21
|
+
when :major ; major
|
22
|
+
when :minor ; minor
|
23
|
+
when :both ; major + '.' + minor
|
24
|
+
else raise ArgumentError.new('Wrong argument type, expected :major, :minor or :both.')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def change_version (value, type = :major)
|
29
|
+
case type
|
30
|
+
when :major ; write_property('CFBundleShortVersionString', value)
|
31
|
+
when :minor ; write_property('CFBundleVersion', value)
|
32
|
+
else raise ArgumentError.new('Wrong argument type, expected :major or :minor.')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def increment_version (type = :major)
|
37
|
+
cv = version(type)
|
38
|
+
nv = cv.nil? ? '0' : cv.next
|
39
|
+
|
40
|
+
change_version(nv, type)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def plist_path
|
46
|
+
root.absolute_path(build_settings['INFOPLIST_FILE'])
|
47
|
+
end
|
48
|
+
|
49
|
+
def read_property (key)
|
50
|
+
file = File.new(plist_path)
|
51
|
+
doc = REXML::Document.new(file)
|
52
|
+
|
53
|
+
doc.elements.each("plist/dict/key") do |e|
|
54
|
+
return e.next_element.text if e.text == key
|
55
|
+
end
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
|
59
|
+
def write_property (key, value)
|
60
|
+
file = File.new(plist_path)
|
61
|
+
doc = REXML::Document.new(file)
|
62
|
+
|
63
|
+
doc.elements.each("plist/dict/key") do |e|
|
64
|
+
e.next_element.text = value if e.text == key
|
65
|
+
end
|
66
|
+
|
67
|
+
formatter = REXML::Formatters::Default.new
|
68
|
+
File.open(plist_path, 'w') do |data|
|
69
|
+
formatter.write(doc, data)
|
70
|
+
end
|
71
|
+
nil
|
72
|
+
end
|
73
|
+
|
14
74
|
end
|
15
75
|
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe XcodeProject::XCBuildConfiguration do
|
4
|
+
before(:each) { @data = prepare_example_project.read }
|
5
|
+
let(:obj) { obj = @data.target('example').config('Release') }
|
6
|
+
|
7
|
+
describe "#plist_path" do
|
8
|
+
it "returns plist file path" do
|
9
|
+
obj.send(:plist_path).should eql(example_project_dir.join('example/example-Info.plist'))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#version" do
|
14
|
+
context "by default" do
|
15
|
+
it "returns major version" do
|
16
|
+
obj.version.should eql(obj.version(:major))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
context "if passed :major" do
|
20
|
+
it "returns major version" do
|
21
|
+
obj.version(:major).should eql('1.0')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
context "if passed :minor" do
|
25
|
+
it "returns minor version" do
|
26
|
+
obj.version(:minor).should eql('345')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
context "if passed :both" do
|
30
|
+
it "returns both, major and minor versions" do
|
31
|
+
obj.version(:both).should eql('1.0.345')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#change_version" do
|
37
|
+
let(:version) { '2.0' }
|
38
|
+
|
39
|
+
context "by default" do
|
40
|
+
it "changes major version" do
|
41
|
+
obj.change_version(version)
|
42
|
+
obj.version(:major).should eql(version)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "if passed :major" do
|
47
|
+
it "changes major version" do
|
48
|
+
obj.change_version(version, :major)
|
49
|
+
obj.version(:major).should eql(version)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "if passed :minor" do
|
54
|
+
it "changes minor version" do
|
55
|
+
obj.change_version(version, :minor)
|
56
|
+
obj.version(:minor).should eql(version)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#increment_version" do
|
62
|
+
context "by default" do
|
63
|
+
let(:next_version) { '1.1' }
|
64
|
+
|
65
|
+
it "increments major version" do
|
66
|
+
obj.increment_version
|
67
|
+
obj.version(:major).should eql(next_version)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "if passed :major" do
|
72
|
+
let(:next_version) { '1.1' }
|
73
|
+
|
74
|
+
it "increments major version" do
|
75
|
+
obj.increment_version(:major)
|
76
|
+
obj.version(:major).should eql(next_version)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "if passed :minor" do
|
81
|
+
let(:next_version) { '346' }
|
82
|
+
|
83
|
+
it "increments minor version" do
|
84
|
+
obj.increment_version(:minor)
|
85
|
+
obj.version(:minor).should eql(next_version)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#read_property" do
|
91
|
+
let(:key) { 'CFBundleShortVersionString' }
|
92
|
+
let(:value) { '1.0' }
|
93
|
+
|
94
|
+
it "read a property by key from plist file" do
|
95
|
+
obj.send(:read_property, key).should eql(value)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#write_property" do
|
100
|
+
let(:key) { 'CFBundleShortVersionString' }
|
101
|
+
let(:value) { '1.1' }
|
102
|
+
|
103
|
+
it "write value by key to plist file" do
|
104
|
+
obj.send(:write_property, key, value)
|
105
|
+
obj.send(:read_property, key).should eql(value)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 9
|
9
|
+
version: 0.3.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Andrey Nesterov
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-08-
|
17
|
+
date: 2012-08-27 00:00:00 +04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- spec/pbx_project_spec.rb
|
158
158
|
- spec/project_spec.rb
|
159
159
|
- spec/spec_helper.rb
|
160
|
+
- spec/xc_build_configuration_spec.rb
|
160
161
|
- spec/xc_configuration_list_spec.rb
|
161
162
|
- xcodeproject.gemspec
|
162
163
|
has_rdoc: true
|
@@ -201,4 +202,5 @@ test_files:
|
|
201
202
|
- spec/pbx_project_spec.rb
|
202
203
|
- spec/project_spec.rb
|
203
204
|
- spec/spec_helper.rb
|
205
|
+
- spec/xc_build_configuration_spec.rb
|
204
206
|
- spec/xc_configuration_list_spec.rb
|