timewizard 0.2.4.pre.alpha.pre.41 → 0.3.0.pre.alpha.pre.47

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,115 +1,133 @@
1
+ #
2
+ # Copyright (C) 2015 Richard Harrah <topplethenunnery@gmail.com>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
1
21
  require 'xcodeproj'
2
- require 'find'
3
22
  require 'versionomy'
23
+ require 'timewizard/versioner'
4
24
  require 'timewizard/utils/wizardry'
5
25
 
6
26
  module Timewizard
7
27
  module Versioner
8
- class Apple
9
- attr_accessor :dir
10
- attr_reader :proj
11
- attr_reader :plists
12
- attr_reader :old_bundle_version
13
- attr_reader :old_build_number
14
- attr_accessor :new_bundle_version
15
- attr_accessor :new_build_number
16
-
17
- def initialize(dir)
18
- @dir = dir
19
- @proj = nil
20
- @plists = []
28
+ class Apple < Timewizard::Versioner::Base
29
+
30
+ #
31
+ # Public functions (inherited from parent)
32
+ #
33
+ public
34
+
35
+ def read_build_numbers
36
+ read_file
37
+ find_build_numbers
38
+ end
39
+
40
+ def read_version_numbers
41
+ read_file
42
+ find_version_numbers
43
+ end
44
+
45
+ def write_build_numbers
46
+ change_build_numbers
47
+ write_file
21
48
  end
22
49
 
23
- def find_xcode_project()
24
- if @dir.nil?
25
- raise "directory cannot be nil"
50
+ def write_version_numbers
51
+ change_version_numbers
52
+ write_file
53
+ end
54
+
55
+ #
56
+ # Private functions (implementation specific)
57
+ #
58
+ private
59
+
60
+ def read_file
61
+ if @file.nil?
62
+ raise 'file is nil and cannot be read'
26
63
  end
27
- if @dir.end_with? ".xcodeproj"
28
- @proj = File.absolute_path(@dir)
29
- else
30
- Find.find(@dir) do |path|
31
- unless path.to_s.end_with? ".xcodeproj"
32
- next
33
- end
34
- @proj = path
35
- end
64
+
65
+ @file_contents = {}
66
+
67
+ if File.exist?(@file)
68
+ @file_contents = Xcodeproj::PlistHelper.read @file
36
69
  end
37
- @proj
70
+
71
+ @file_contents
38
72
  end
39
73
 
40
- def find_plists()
41
- if @proj.nil?
42
- raise "there is no .xcodeproj"
43
- end
44
- directory = File.dirname(@proj.to_s)
45
- unless Dir.exist?(directory)
46
- raise "proj is not in a directory"
74
+ def write_file
75
+ if @file.nil?
76
+ raise 'file is nil and cannot be written'
47
77
  end
48
- @plists = []
49
- Find.find(directory) do |p|
50
- if /^.*Info\.plist$/ =~ p
51
- @plists << p
52
- end
78
+ if @file_contents.nil?
79
+ raise 'file_contents is nil and cannot be written'
53
80
  end
54
- @plists
81
+ Xcodeproj::PlistHelper.write(@file_contents, @file)
55
82
  end
56
83
 
57
- def find_bundle_version(lists)
58
- find_bundle_and_build_version(lists)[0]
84
+ def find_build_numbers
85
+ find_build_and_version_numbers
86
+ [@old_build_number, @new_build_number]
59
87
  end
60
88
 
61
- def find_build_number(lists)
62
- find_bundle_and_build_version(lists)[1]
89
+ def find_version_numbers
90
+ find_build_and_version_numbers
91
+ [@old_version_number, @new_version_number]
63
92
  end
64
93
 
65
- def change_bundle_version(versions, change_to = '-1')
66
- unless change_to != '-1'
67
- @new_bundle_version = versions[0]
68
- versions
94
+ def find_build_and_version_numbers
95
+ if @file_contents.nil?
96
+ read_file
69
97
  end
70
- ver = Timewizard::Utils::Wizardry.only_version change_to
71
- parsed = Versionomy.parse(ver, Versionomy::Format.get('rubygems'))
72
- versions[0] = parsed.unparse
73
- @new_bundle_version = versions[0]
74
- versions
75
- end
76
98
 
77
- def change_build_number(versions, change_to = '-1')
78
- if change_to == '-1'
79
- ver = Timewizard::Utils::Wizardry.only_version @old_build_number.to_s
80
- parsed = Versionomy.parse(ver, Versionomy::Format.get('rubygems'))
81
- parsed = parsed.bump(parsed.parts.length - 1)
82
- versions[1] = parsed.unparse
83
- @new_build_number = versions[1]
84
- else
85
- ver = Timewizard::Utils::Wizardry.only_version change_to
86
- parsed = Versionomy.parse ver
87
- versions[1] = parsed.unparse
88
- @new_build_number = versions[1]
89
- end
90
- versions
91
- end
99
+ build_num = Timewizard::Utils::Wizardry.only_version(@file_contents["CFBundleVersion"]) || '0'
100
+ version_num = Timewizard::Utils::Wizardry.only_version(@file_contents["CFBundleShortVersionString"]) || '0'
92
101
 
93
- def find_bundle_and_build_version(lists)
94
- versions = []
95
- for list in lists do
96
- list_hash = Xcodeproj::PlistHelper.read list
97
- versions[0] ||= list_hash["CFBundleShortVersionString"]
98
- versions[1] ||= list_hash["CFBundleVersion"]
102
+ parsed_build_num = Versionomy.parse(build_num, Versionomy::Format.get('rubygems'))
103
+ parsed_version_num = Versionomy.parse(version_num, Versionomy::Format.get('rubygems'))
99
104
 
100
- @old_bundle_version = versions[0]
101
- @old_build_number = versions[1]
105
+ @old_build_number = parsed_build_num.unparse
106
+ @old_version_number = parsed_version_num.unparse
107
+
108
+ @new_build_number = parsed_build_num.bump(parsed_build_num.parts.length - 1).unparse
109
+ @new_version_number = @old_version_number
110
+ self
111
+ end
112
+
113
+ def change_build_numbers
114
+ if @file_contents.nil?
115
+ read_file
102
116
  end
103
- versions
117
+ if @new_build_number.nil?
118
+ read_build_numbers
119
+ end
120
+ @file_contents["CFBundleVersion"] = @new_build_number.to_s || @file_contents["CFBundleVersion"]
104
121
  end
105
122
 
106
- def write_plists(versions)
107
- for list in @plists do
108
- list_hash = Xcodeproj::PlistHelper.read list
109
- list_hash["CFBundleShortVersionString"] = versions[0] || list_hash["CFBundleShortVersionString"]
110
- list_hash["CFBundleVersion"] = versions[0] || list_hash["CFBundleVersion"]
111
- Xcodeproj::PlistHelper.write(list_hash, list)
123
+ def change_version_numbers
124
+ if @file_contents.nil?
125
+ read_file
126
+ end
127
+ if @new_build_number.nil?
128
+ read_build_numbers
112
129
  end
130
+ @file_contents["CFBundleShortVersionString"] = @new_build_number.to_s || @file_contents["CFBundleShortVersionString"]
113
131
  end
114
132
 
115
133
  end
@@ -1,5 +1,57 @@
1
+ #
2
+ # Copyright (C) 2015 Richard Harrah <topplethenunnery@gmail.com>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
1
21
  module Timewizard
2
22
  module Versioner
23
+ class Base
24
+ attr_reader :file
25
+ attr_reader :old_build_number
26
+ attr_reader :old_version_number
27
+ attr_accessor :new_build_number
28
+ attr_accessor :new_version_number
29
+
30
+ def initialize(path_to_file)
31
+ if path_to_file.nil?
32
+ raise "passed in file cannot be nil"
33
+ end
34
+ @file = path_to_file
35
+ end
36
+
37
+ def read_build_numbers()
38
+ # do nothing
39
+ end
40
+
41
+ def read_version_numbers()
42
+ # do nothing
43
+ end
44
+
45
+ def write_build_numbers()
46
+ # do nothing
47
+ end
48
+
49
+ def write_version_numbers()
50
+ # do nothing
51
+ end
52
+
53
+ end
54
+
3
55
  autoload :Android, 'timewizard/versioner/android'
4
56
  autoload :Apple, 'timewizard/versioner/apple'
5
57
  end
data/lib/timewizard.rb CHANGED
@@ -1,5 +1,21 @@
1
- require "timewizard/version"
2
-
3
- module Timewizard
4
- # Your code goes here...
5
- end
1
+ #
2
+ # Copyright (C) 2015 Richard Harrah <topplethenunnery@gmail.com>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+ require 'timewizard/version'
@@ -0,0 +1,33 @@
1
+ require 'timewizard'
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+
5
+ RSpec.configure do |config|
6
+
7
+ config.expect_with :rspec do |expectations|
8
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
9
+ end
10
+
11
+ config.mock_with :rspec do |mocks|
12
+ mocks.verify_partial_doubles = true
13
+ end
14
+
15
+ config.filter_run :focus
16
+ config.run_all_when_everything_filtered = true
17
+
18
+ config.example_status_persistence_file_path = "spec/examples.txt"
19
+
20
+ config.disable_monkey_patching!
21
+
22
+ config.warnings = true
23
+
24
+ if config.files_to_run.one?
25
+ config.default_formatter = 'doc'
26
+ end
27
+
28
+ config.profile_examples = 10
29
+
30
+ config.order = :random
31
+
32
+ Kernel.srand config.seed
33
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.describe Timewizard do
2
+ it 'should have a VERSION constant' do
3
+ expect(Timewizard::VERSION).to_not be_nil
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ require 'timewizard/utils/wizardry'
2
+
3
+ RSpec.describe 'Timewizard::Utils::Wizardry' do
4
+ context '.only_version' do
5
+ it 'should raise an error when arg is nil' do
6
+ expect { Timewizard::Utils::Wizardry.only_version nil }.to raise_error('stringy cannot be null')
7
+ end
8
+
9
+ it 'should return the same value when given a proper version number' do
10
+ base = '0.0.1'
11
+
12
+ expected = '0.0.1'
13
+ actual = Timewizard::Utils::Wizardry.only_version base
14
+
15
+ expect(actual).to eq(expected)
16
+ end
17
+
18
+ it 'should return a version number when given a text string containing a version number' do
19
+ base = 'this is version 0.0.1'
20
+
21
+ expected = '0.0.1'
22
+ actual = Timewizard::Utils::Wizardry.only_version base
23
+
24
+ expect(actual).to eq(expected)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,107 @@
1
+ require 'timewizard/versioner'
2
+
3
+ RSpec.describe 'Timewizard::Versioner::Base' do
4
+
5
+ context '.new' do
6
+ it 'should raise error if arg is nil' do
7
+ expect { Timewizard::Versioner::Base.new nil }.to raise_error("passed in file cannot be nil")
8
+ end
9
+
10
+ it 'should not raise error if arg is not nil' do
11
+ expect { Timewizard::Versioner::Base.new '' }.not_to raise_error
12
+ end
13
+ end
14
+
15
+ before(:context) do
16
+ @versioner = Timewizard::Versioner::Base.new ''
17
+ end
18
+
19
+ context '#file' do
20
+ it 'should be empty string' do
21
+ expect(@versioner.file).to eq('')
22
+ end
23
+ end
24
+
25
+ context '#old_build_number' do
26
+ it 'should be nil' do
27
+ expect(@versioner.old_build_number).to be_nil
28
+ end
29
+ end
30
+
31
+ context '#old_version_number' do
32
+ it 'should be nil' do
33
+ expect(@versioner.old_version_number).to be_nil
34
+ end
35
+ end
36
+
37
+ context '#new_build_number' do
38
+ it 'should be nil' do
39
+ expect(@versioner.new_build_number).to be_nil
40
+ end
41
+ end
42
+
43
+ context '#new_build_number=' do
44
+ it 'should change instance variable' do
45
+ @versioner.new_build_number = '1'
46
+ expect(@versioner.new_build_number).not_to be_nil
47
+ @versioner.new_build_number = nil
48
+ expect(@versioner.new_build_number).to be_nil
49
+ end
50
+ end
51
+
52
+ context '#new_version_number' do
53
+ it 'should be nil' do
54
+ expect(@versioner.new_version_number).to be_nil
55
+ end
56
+ end
57
+
58
+ context '#new_version_number=' do
59
+ it 'should change instance variable' do
60
+ @versioner.new_version_number = '1'
61
+ expect(@versioner.new_version_number).not_to be_nil
62
+ @versioner.new_version_number = nil
63
+ expect(@versioner.new_version_number).to be_nil
64
+ end
65
+ end
66
+
67
+ context '#read_build_numbers' do
68
+ it 'should not change instance variables' do
69
+ expect(@versioner.old_build_number).to be_nil
70
+ expect(@versioner.new_build_number).to be_nil
71
+ @versioner.read_build_numbers
72
+ expect(@versioner.old_build_number).to be_nil
73
+ expect(@versioner.new_build_number).to be_nil
74
+ end
75
+ end
76
+
77
+ context '#read_version_numbers' do
78
+ it 'should not change instance variables' do
79
+ expect(@versioner.old_version_number).to be_nil
80
+ expect(@versioner.new_version_number).to be_nil
81
+ @versioner.read_version_numbers
82
+ expect(@versioner.old_version_number).to be_nil
83
+ expect(@versioner.new_version_number).to be_nil
84
+ end
85
+ end
86
+
87
+ context '#write_build_numbers' do
88
+ it 'should not change instance variables' do
89
+ expect(@versioner.old_build_number).to be_nil
90
+ expect(@versioner.new_build_number).to be_nil
91
+ @versioner.write_build_numbers
92
+ expect(@versioner.old_build_number).to be_nil
93
+ expect(@versioner.new_build_number).to be_nil
94
+ end
95
+ end
96
+
97
+ context '#write_version_numbers' do
98
+ it 'should not change instance variables' do
99
+ expect(@versioner.old_version_number).to be_nil
100
+ expect(@versioner.new_version_number).to be_nil
101
+ @versioner.write_version_numbers
102
+ expect(@versioner.old_version_number).to be_nil
103
+ expect(@versioner.new_version_number).to be_nil
104
+ end
105
+ end
106
+
107
+ end
data/timewizard.gemspec CHANGED
@@ -1,29 +1,61 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'timewizard/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "timewizard"
8
- spec.version = Timewizard::VERSION
9
- spec.version = "#{spec.version}-alpha-#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV['TRAVIS'] && ENV['TRAVIS_BRANCH'] == 'development'
10
- spec.authors = ["Richard Harrah"]
11
- spec.email = ["topplethenunnery@gmail.com"]
12
-
13
- spec.summary = %q{A gem for incrementing and decrementing iOS and Android app versions.}
14
- spec.homepage = "https://github.com/Nunnery/timewizard"
15
- spec.license = "MIT"
16
-
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
21
-
22
- spec.add_development_dependency "bundler", "~> 1.10"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4"
25
- spec.add_development_dependency "minitest", "~> 5.8"
26
-
27
- spec.add_dependency "versionomy", "~> 0.4"
28
- spec.add_dependency "xcodeproj", "~> 0.26"
29
- end
2
+
3
+ require 'yaml'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gemspec = YAML.load_file('gemspec.yml')
7
+
8
+ gem.name = gemspec.fetch('name')
9
+ gem.version = gemspec.fetch('version') do
10
+ lib_dir = File.join(File.dirname(__FILE__), 'lib')
11
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
12
+
13
+ require 'timewizard/version'
14
+ Timewizard::VERSION
15
+ end
16
+ gem.version = "#{gem.version}-alpha-#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV['TRAVIS_BRANCH'] == 'development'
17
+
18
+ gem.summary = gemspec['summary']
19
+ gem.description = gemspec['description']
20
+ gem.licenses = Array(gemspec['license'])
21
+ gem.authors = Array(gemspec['authors'])
22
+ gem.email = gemspec['email']
23
+ gem.homepage = gemspec['homepage']
24
+
25
+ glob = lambda { |patterns| gem.files & Dir[*patterns] }
26
+
27
+ gem.files = `git ls-files`.split($/)
28
+ gem.files = glob[gemspec['files']] if gemspec['files']
29
+
30
+ gem.executables = gemspec.fetch('executables') do
31
+ glob['bin/*'].map { |path| File.basename(path) }
32
+ end
33
+ gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
34
+
35
+ gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
36
+ gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
37
+ gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,rdoc}']
38
+
39
+ gem.require_paths = Array(gemspec.fetch('require_paths') {
40
+ %w[ext lib].select { |dir| File.directory?(dir) }
41
+ })
42
+
43
+ gem.requirements = gemspec['requirements']
44
+ gem.required_ruby_version = gemspec['required_ruby_version']
45
+ gem.required_rubygems_version = gemspec['required_rubygems_version']
46
+ gem.post_install_message = gemspec['post_install_message']
47
+
48
+ split = lambda { |string| string.split(/,\s*/) }
49
+
50
+ if gemspec['dependencies']
51
+ gemspec['dependencies'].each do |name, versions|
52
+ gem.add_dependency(name, split[versions])
53
+ end
54
+ end
55
+
56
+ if gemspec['development_dependencies']
57
+ gemspec['development_dependencies'].each do |name, versions|
58
+ gem.add_development_dependency(name, split[versions])
59
+ end
60
+ end
61
+ end