tumbler 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,14 @@
1
+ == 0.0.6
2
+
3
+ * corrected docs. correct version (Joshua Hull, a3ee9bc)
4
+ * new version scheme (Joshua Hull, 631c067)
5
+ * restructure (Joshua Hull, 641ea47)
6
+ * create Tumbler config on update (Joshua Hull, e26b306)
7
+
8
+ == 0.0.5
9
+
10
+ * remove push task (Joshua Hull, b85b730)
11
+
1
12
  == 0.0.4
2
13
 
3
14
 
@@ -19,14 +19,10 @@ For existing projects, you need to configure it to tell Tumbler to do its work.
19
19
  gem_name 'my_awesome_gem'
20
20
 
21
21
  # Use this file to track the version
22
- use_version do
23
- filename 'VERSION'
24
- end
22
+ version_file 'lib/my_awesome_gem/version.rb'
25
23
 
26
24
  # Use this file to hang onto your changelog
27
- use_changelog do
28
- filename 'CHANGELOG'
29
- end
25
+ changelog_file 'CHANGELOG'
30
26
 
31
27
  Your version number has to only be something parsable by Versionomy. The changelog will automatically be updated when you do releases.
32
28
 
data/Tumbler CHANGED
@@ -1,9 +1,4 @@
1
1
  gem_name 'tumbler'
2
2
 
3
- use_version do
4
- filename 'VERSION'
5
- end
6
-
7
- use_changelog do
8
- filename 'CHANGELOG'
9
- end
3
+ version_file 'lib/tumbler/version.rb'
4
+ changelog_file 'CHANGELOG'
@@ -0,0 +1,17 @@
1
+ source :rubygems
2
+
3
+ # your dependencies go here
4
+ # gem 'nokogiri'
5
+ <% @dependencies.each do |dep|%>
6
+ gem <%=dep.name.inspect%>, <%=dep.requirement.to_s.inspect%>
7
+ <% end %>
8
+
9
+ group :development do
10
+ # your development dependencies go here
11
+ # gem 'rake'
12
+ # gem 'rspect'
13
+ <% development_dependencies.each do |dep| %>
14
+ gem <%=dep.name.inspect%>, <%=dep.requirement.to_s.inspect%>
15
+ <% end %>
16
+ end
17
+
File without changes
@@ -0,0 +1,9 @@
1
+ gem_name <%=@name.inspect%>
2
+
3
+ <% if @version %>
4
+ version_file 'lib/<%=@name%>/version.rb'
5
+ <% end %>
6
+
7
+ <% if @changelog %>
8
+ changelog_file <%=@changelog.inspect%>
9
+ <% end %>
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+ module <%=constant_name%> #:nodoc
3
+ VERSION = '<%=version%>'
4
+ end
@@ -11,169 +11,19 @@ require 'tumbler/updater'
11
11
  require 'tumbler/rake_tasks'
12
12
  require 'tumbler/version'
13
13
  require 'tumbler/gemspec_helper'
14
- require 'tumbler/changelog'
15
14
  require 'tumbler/generate'
16
15
  require 'tumbler/gem'
17
16
  require 'tumbler/cli'
17
+ require 'tumbler/manager'
18
18
 
19
- class Tumbler
20
- def self.load_version(filename = Version::DEFAULT_FILE)
21
- File.read(File.join(__DIR__, '..', filename))
22
- end
23
-
24
- VERSION = Tumbler.load_version
25
-
26
- include Runner
27
-
28
- Change = Struct.new(:hash, :author, :summary)
29
-
30
- attr_reader :base, :version, :changelog, :gem, :name
31
- attr_accessor :noop
32
-
19
+ module Tumbler
33
20
  def self.use_rake_tasks(name = nil)
34
21
  root = File.dirname(Callsite.parse(caller).find{|c| c.filename =~ /Rakefile/}.filename)
35
22
  Tumbler::RakeTasks.register(File.expand_path(root), name)
36
23
  end
37
24
 
38
25
  def self.load(base)
39
- File.exist?(File.join(base, 'Tumbler')) ? new(base) : nil
40
- end
41
-
42
- def set_version(version)
43
- @version = Version.new
44
- end
45
-
46
- def gem_name(name)
47
- @name = name
48
- end
49
-
50
- def bundler
51
- @definition ||= Bundler::Dsl.evaluate(gemfile_path)
52
- end
53
-
54
- def config_path
55
- File.join(@base, 'Tumbler')
56
- end
57
-
58
- def gemfile_path
59
- File.join(@base, 'Gemfile')
60
- end
61
-
62
- def gemspec_path
63
- File.join(@base, "#{@name}.gemspec")
64
- end
65
-
66
- def lockfile_path
67
- File.join(@base, 'Gemfile.lock')
68
- end
69
-
70
- def use_version(&block)
71
- @version = Version.new(self, &block)
72
- end
73
-
74
- def use_gem(&block)
75
- @gem.instance_eval(block)
76
- end
77
-
78
- def use_changelog(&block)
79
- @changelog = Changelog.new(self, &block)
80
- end
81
-
82
- def reset
83
- @version = nil
84
- @changelog = nil
85
- end
86
-
87
- def bump_and_commit(field)
88
- guard_clean
89
- @changelog.update if @changelog
90
- bump(field)
91
- if @changelog
92
- @changelog.write_version_header
93
- @changelog.commit
94
- end
95
- end
96
-
97
- def tag_and_push
98
- guard_clean
99
- guard_already_tagged
100
- tag
101
- push
102
- end
103
-
104
- def bump_and_push(field)
105
- revert_on_error {
106
- bump_and_commit(field)
107
- tag_and_push
108
- }
109
- end
110
-
111
- def current_revision
112
- sh('git show --pretty=format:%H').split(/\n/)[0].strip
113
- end
114
-
115
- def revert_on_error
116
- current_ref = current_revision
117
- begin
118
- yield
119
- rescue
120
- sh "git reset --hard #{current_ref}"
121
- raise
122
- end
123
- end
124
-
125
- def guard_clean
126
- clean? or raise("There are files that need to be committed first.")
127
- end
128
-
129
- def guard_already_tagged
130
- sh('git tag').split(/\n/).include?(@version.to_s) and raise("This tag has already been committed to the repo.")
131
- end
132
-
133
- def bump(level)
134
- from = @version.to_s
135
- @version.bump(level)
136
- @version.commit(from)
137
- end
138
-
139
- def clean?
140
- sh("git ls-files -dm").split("\n").size.zero?
141
- end
142
-
143
- def push
144
- sh "git push --all"
145
- sh "git push --tags"
146
- end
147
-
148
- def tag
149
- sh "git tag #{@version.to_s}"
150
- end
151
-
152
- def commit(msg)
153
- sh "git commit #{@version.basefile} -m'#{msg}'"
154
- end
155
-
156
- def tags
157
- sh('git tag').split(/\n/)
158
- end
159
-
160
- def reload
161
- reset
162
- @gem = Gem.new(self)
163
- instance_eval(File.read(config_path), config_path, 1)
164
- end
165
-
166
- def latest_changes
167
- changes = sh("git log --pretty=format:'%h (%aN) %s' --no-color #{@version}..HEAD").
168
- scan(/([a-f0-9]{7}) \((.*?)\) (.*)$/).
169
- map{|line| Change.new(line[0], line[1], line[2])}
170
- end
171
-
172
- private
173
- def initialize(base)
174
- @base = base
175
- reload
176
- @noop = true if ENV['DRY'] == '1'
26
+ File.exist?(File.join(base, 'Tumbler')) ? Manager.new(base) : nil
177
27
  end
178
28
 
179
29
  end
@@ -1,6 +1,6 @@
1
1
  require 'optparse'
2
2
 
3
- class Tumbler
3
+ module Tumbler
4
4
  class CLI
5
5
  def self.run(args)
6
6
  CLI.new(args).run
@@ -8,8 +8,7 @@ class Tumbler
8
8
 
9
9
  def initialize(args)
10
10
  @options = {
11
- :changelog => Changelog::DEFAULT_FILE,
12
- :version => Version::INITIAL_VERSION
11
+ :changelog => Manager::Changelog::DEFAULT_FILE,
13
12
  }
14
13
  parser.parse!(args)
15
14
  end
@@ -37,7 +36,7 @@ class Tumbler
37
36
  @options[:version] = v
38
37
  end
39
38
 
40
- opts.on("-nv", "--no-value", "Disable version") do |v|
39
+ opts.on("-nv", "--no-version", "Disable version") do |v|
41
40
  @options[:version] = nil
42
41
  end
43
42
 
@@ -1,4 +1,4 @@
1
- class Tumbler
1
+ module Tumbler
2
2
  class Gem
3
3
  include Runner
4
4
 
@@ -1,4 +1,4 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'tumbler') unless Kernel.const_defined?(:Tumbler)
2
2
  root = File.expand_path(File.dirname(Callsite.parse(caller).find{|c| c.filename =~ /\.gemspec$/}.filename))
3
3
  Tumbler.send(:remove_const, :Gemspec) if (Tumbler.const_defined?(:Gemspec))
4
- Tumbler::Gemspec = Tumbler::GemspecHelper.new(Tumbler.new(root))
4
+ Tumbler::Gemspec = Tumbler::GemspecHelper.new(Tumbler.load(root))
@@ -1,4 +1,4 @@
1
- class Tumbler
1
+ module Tumbler
2
2
  class GemspecHelper
3
3
  def initialize(manager)
4
4
  @manager = manager
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'erb'
3
3
 
4
- class Tumbler
4
+ module Tumbler
5
5
  class Generate
6
6
 
7
7
  include Runner
@@ -32,14 +32,18 @@ class Tumbler
32
32
  @name = name
33
33
  @dependencies = []
34
34
  @development_dependencies = []
35
- @version = Version::INITIAL_VERSION
36
- @changelog = Changelog::DEFAULT_FILE
35
+ @version = Manager::Version::INITIAL_VERSION
36
+ @changelog = Manager::Changelog::DEFAULT_FILE
37
+ end
38
+
39
+ def constant_name
40
+ @name.split('_').map{|p| p.capitalize}.join
37
41
  end
38
42
 
39
43
  def write
40
44
  write_gemspec
41
45
  write_gemfile
42
- write_version
46
+ write_version(@version)
43
47
  write_changelog
44
48
  write_rakefile
45
49
  write_tumbler_config
@@ -62,18 +66,13 @@ class Tumbler
62
66
  File.join(@base, 'Tumbler')
63
67
  end
64
68
 
65
- def init_version
66
- return unless @version
67
- File.open(@version.file, "w") {|f| f.puts @version.value.to_s} unless File.exist?(@version.file)
69
+ def write_version(version)
70
+ FileUtils.mkdir_p(File.dirname(version_path))
71
+ File.open(version_path, 'w') {|f| f << generate_version(version) }
68
72
  end
69
-
70
- def init_changelog
71
- return unless @changelog
72
- File.open(@changelog.file, "w") {|f| f << ''} unless File.exist?(@changelog.file)
73
- end
74
-
75
- def write_version
76
- File.open(File.join(@base, Version::DEFAULT_FILE), 'w') {|f| f << @version }
73
+
74
+ def version_path
75
+ File.join(@base, 'lib', @name, 'version.rb')
77
76
  end
78
77
 
79
78
  def write_gemfile
@@ -109,23 +108,21 @@ class Tumbler
109
108
  end
110
109
 
111
110
  def template_path(path)
112
- File.join(File.dirname(__FILE__), '..', '..', 'template', path)
111
+ File.join(File.dirname(__FILE__), '..', 'template', path)
113
112
  end
114
113
 
115
114
  def generate_tumbler_conf
116
- template = ERB.new(File.read(template_path('generic.Tumbler.erb')))
115
+ template = ERB.new(File.read(template_path('Tumbler.erb')))
117
116
  template.result(binding)
118
117
  end
119
118
 
120
119
  def generate_gemfile
121
- template = ERB.new <<-EOF
122
- source :rubygems
123
-
124
- <% @dependencies.each do |dep|%>gem <%=dep.name.inspect%>, <%=dep.requirement.to_s.inspect%><%="\n"%><% end %>
125
- group(:development) do
126
- <% development_dependencies.each do |dep|%> gem <%=dep.name.inspect%>, <%=dep.requirement.to_s.inspect%><%="\n"%><% end %>
127
- end
128
- EOF
120
+ template = ERB.new(File.read(template_path('Gemfile.erb')))
121
+ template.result(binding)
122
+ end
123
+
124
+ def generate_version(version)
125
+ template = ERB.new(File.read(template_path('version.rb.erb')))
129
126
  template.result(binding)
130
127
  end
131
128
 
@@ -0,0 +1,161 @@
1
+ require 'tumbler/manager/changelog'
2
+ require 'tumbler/manager/version'
3
+
4
+ module Tumbler
5
+ class Manager
6
+ include Runner
7
+
8
+ Change = Struct.new(:hash, :author, :summary)
9
+
10
+ attr_reader :base, :version, :changelog, :gem, :name
11
+ attr_accessor :noop
12
+
13
+ def default_version_file
14
+ File.join('lib', name, 'version.rb')
15
+ end
16
+
17
+ def default_changelog_file
18
+ Changelog::DEFAULT_FILE
19
+ end
20
+
21
+ def gem_name(name)
22
+ @name = name
23
+ end
24
+
25
+ def bundler
26
+ @definition ||= Bundler::Dsl.evaluate(gemfile_path)
27
+ end
28
+
29
+ def config_path
30
+ File.join(@base, 'Tumbler')
31
+ end
32
+
33
+ def gemfile_path
34
+ File.join(@base, 'Gemfile')
35
+ end
36
+
37
+ def gemspec_path
38
+ File.join(@base, "#{@name}.gemspec")
39
+ end
40
+
41
+ def lockfile_path
42
+ File.join(@base, 'Gemfile.lock')
43
+ end
44
+
45
+ def version_file(file = default_version_file, &block)
46
+ @version = Manager::Version.new(self)
47
+ @version.filename(file)
48
+ @version.instance_eval(&block) if block
49
+ @version.reload
50
+ @version
51
+ end
52
+
53
+ def use_gem(&block)
54
+ @gem.instance_eval(block)
55
+ end
56
+
57
+ def changelog_file(file = default_changelog_file, &block)
58
+ @changelog = Changelog.new(self)
59
+ @changelog.filename(file)
60
+ @changelog.instance_eval(&block) if block
61
+ @changelog
62
+ end
63
+
64
+ def reset
65
+ @version = nil
66
+ @changelog = nil
67
+ end
68
+
69
+ def bump_and_commit(field)
70
+ guard_clean
71
+ @changelog.update if @changelog
72
+ bump(field)
73
+ if @changelog
74
+ @changelog.write_version_header
75
+ @changelog.commit
76
+ end
77
+ end
78
+
79
+ def tag_and_push
80
+ guard_clean
81
+ guard_already_tagged
82
+ tag
83
+ push
84
+ end
85
+
86
+ def bump_and_push(field)
87
+ revert_on_error {
88
+ bump_and_commit(field)
89
+ tag_and_push
90
+ }
91
+ end
92
+
93
+ def current_revision
94
+ sh('git show --pretty=format:%H').split(/\n/)[0].strip
95
+ end
96
+
97
+ def revert_on_error
98
+ current_ref = current_revision
99
+ begin
100
+ yield
101
+ rescue
102
+ sh "git reset --hard #{current_ref}"
103
+ raise
104
+ end
105
+ end
106
+
107
+ def guard_clean
108
+ clean? or raise("There are files that need to be committed first.")
109
+ end
110
+
111
+ def guard_already_tagged
112
+ sh('git tag').split(/\n/).include?(@version.to_s) and raise("This tag has already been committed to the repo.")
113
+ end
114
+
115
+ def bump(level)
116
+ from = @version.to_s
117
+ @version.bump(level)
118
+ @version.commit(from)
119
+ end
120
+
121
+ def clean?
122
+ sh("git ls-files -dm").split("\n").size.zero?
123
+ end
124
+
125
+ def push
126
+ sh "git push --all"
127
+ sh "git push --tags"
128
+ end
129
+
130
+ def tag
131
+ sh "git tag #{@version.to_s}"
132
+ end
133
+
134
+ def commit(msg)
135
+ sh "git commit #{@version.basefile} -m'#{msg}'"
136
+ end
137
+
138
+ def tags
139
+ sh('git tag').split(/\n/)
140
+ end
141
+
142
+ def reload
143
+ reset
144
+ @gem = Gem.new(self)
145
+ instance_eval(File.read(config_path), config_path, 1)
146
+ end
147
+
148
+ def latest_changes
149
+ changes = sh("git log --pretty=format:'%h (%aN) %s' --no-color #{@version}..HEAD").
150
+ scan(/([a-f0-9]{7}) \((.*?)\) (.*)$/).
151
+ map{|line| Change.new(line[0], line[1], line[2])}
152
+ end
153
+
154
+ private
155
+ def initialize(base)
156
+ @base = base
157
+ reload
158
+ @noop = true if ENV['DRY'] == '1'
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,64 @@
1
+ require 'tempfile'
2
+ require 'fileutils'
3
+
4
+ module Tumbler
5
+ class Manager
6
+ class Changelog
7
+ include Runner
8
+
9
+ DEFAULT_FILE = 'CHANGELOG'
10
+
11
+ attr_reader :file
12
+
13
+ def initialize(manager, &block)
14
+ @manager = manager
15
+ instance_eval(&block) if block
16
+ end
17
+
18
+ def filename(file)
19
+ @basefile = file
20
+ @file = File.join(@manager.base, file)
21
+ end
22
+
23
+ def write_version_header
24
+ prepend "== #{@manager.version}\n\n"
25
+ end
26
+
27
+ def prepend(data)
28
+ if @manager.noop
29
+ @manager.dry "Prepending #{data} to #{@basefile}"
30
+ else
31
+ Tempfile.open('changelog') do |tmp|
32
+ tmp.puts data
33
+ File.open(@file) do |f|
34
+ f.each do |line|
35
+ tmp << line
36
+ end
37
+ end
38
+ tmp.close
39
+ FileUtils.copy(tmp.path, @file)
40
+ File.unlink(tmp.path)
41
+ end
42
+ end
43
+ end
44
+
45
+ def update
46
+ ensure_existence
47
+ prepend("\n")
48
+ prepend(@manager.latest_changes.inject('') { |changes, change| changes << "* #{change.summary} (#{change.author}, #{change.hash})\n" })
49
+ end
50
+
51
+ def ensure_existence
52
+ File.open(@file, 'w') {|f| f << ''} unless File.exist?(@file)
53
+ end
54
+
55
+ def commit
56
+ sh "git commit #{@basefile} -m'Updated changelog'"
57
+ end
58
+
59
+ def base
60
+ @manager.base
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,66 @@
1
+ module Tumbler
2
+ class Manager
3
+ class Version
4
+ include Runner
5
+
6
+ attr_reader :file, :basefile, :field_names
7
+
8
+ DEFAULT_FIELD = [:major, :minor, :tiny]
9
+ INITIAL_VERSION = '0.0.0'
10
+
11
+ def initialize(manager, &block)
12
+ @manager = manager
13
+ filename(manager.default_version_file)
14
+ fields(DEFAULT_FIELD)
15
+ instance_eval(&block) if block
16
+ end
17
+
18
+ def fields(f)
19
+ @field_names = (f == :all ? @version.field_names : f)
20
+ end
21
+
22
+ def reload
23
+ @version = Versionomy.parse(File.exist?(file) ? extract : '0.0.0')
24
+ end
25
+
26
+ def extract
27
+ File.read(@file)[/Version\s*=\s*['"](.*?)['"]/i, 1]
28
+ end
29
+
30
+ def generate_with_new(version)
31
+ File.read(@file).gsub(/(Version\s*=\s*['"])(.*?)(['"])/i, "\\1#{version.to_s}\\3")
32
+ end
33
+
34
+ def filename(file)
35
+ @basefile = file
36
+ @file = File.join(@manager.base, file)
37
+ end
38
+
39
+ def value
40
+ @version
41
+ end
42
+
43
+ def to_s
44
+ value.to_s
45
+ end
46
+
47
+ def bump(level)
48
+ if @manager.noop
49
+ @manager.dry "Bumping version to #{bump(level).to_s}"
50
+ else
51
+ new_file = generate_with_new(@version.bump(level).to_s)
52
+ File.open(file, 'w') {|f| f << new_file }
53
+ reload
54
+ end
55
+ end
56
+
57
+ def commit(from)
58
+ sh "git commit #{@basefile} -m'Bumped version from #{from} to #{to_s}'"
59
+ end
60
+
61
+ def base
62
+ @manager.base
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,4 +1,4 @@
1
- class Tumbler
1
+ module Tumbler
2
2
  class RakeTasks
3
3
 
4
4
  def self.register(base, name)
@@ -59,12 +59,6 @@ class Tumbler
59
59
  task :release do
60
60
  @manager.bump_and_push(field)
61
61
  end
62
-
63
- desc "Bump version from #{@manager.version.to_s} -> #{@manager.version.value.bump(field).to_s} and push"
64
- task :release do
65
- @manager.bump_and_push(field)
66
- @manager.gem.push
67
- end
68
62
  end
69
63
  end
70
64
  end
@@ -1,4 +1,4 @@
1
- class Tumbler
1
+ module Tumbler
2
2
  module Runner
3
3
 
4
4
  attr_accessor :noop
@@ -2,9 +2,8 @@ require 'net/http'
2
2
  require 'uri'
3
3
  require 'json'
4
4
 
5
- class Tumbler
5
+ module Tumbler
6
6
  class Updater
7
-
8
7
  def initialize(dir, opts = nil)
9
8
  @dir = dir
10
9
  @name = opts && opts[:name] || File.basename(File.expand_path(dir))
@@ -16,6 +15,13 @@ class Tumbler
16
15
  upgrade_version
17
16
  upgrade_changelog
18
17
  upgrade_rakefile
18
+ upgrade_tumbler_config
19
+ end
20
+
21
+ def upgrade_tumbler_config
22
+ unless File.exist?(tumbler_config_path)
23
+ Tumbler::Generate.app(@dir, @name).write_tumbler_config
24
+ end
19
25
  end
20
26
 
21
27
  def upgrade_deps
@@ -40,13 +46,13 @@ raise # (see below)
40
46
  # go to rubygems and get it
41
47
  gem_data = JSON.parse(Net::HTTP.get(URI.parse("http://rubygems.org/api/v1/gems/#{URI.escape(@name)}.json")))
42
48
  version = gem_data['version']
43
- File.open(version_path, 'w') {|f| f << version}
49
+ Tumbler::Generate.app(@dir, @name).write_version(version)
44
50
  end
45
51
  end
46
52
 
47
53
  def upgrade_changelog
48
54
  unless File.exists?(changelog_path)
49
- File.open(changelog_path, 'w'){ |f| f << '' }
55
+ Tumbler::Generate.app(@dir, @name).write_changelog
50
56
  end
51
57
  end
52
58
 
@@ -62,6 +68,10 @@ raise # (see below)
62
68
  File.join(@dir, 'Rakefile')
63
69
  end
64
70
 
71
+ def tumbler_config_path
72
+ File.join(@dir, 'Tumbler')
73
+ end
74
+
65
75
  def create_rakefile
66
76
  File.open(rakefile_path, 'w') { |f|
67
77
  f.puts "require 'tumbler'\nnTumbler.use_rake_tasks"
@@ -69,11 +79,11 @@ raise # (see below)
69
79
  end
70
80
 
71
81
  def version_path
72
- File.join(@dir, Version::DEFAULT_FILE)
82
+ File.join(@dir, 'lib', @name, 'version.rb')
73
83
  end
74
84
 
75
85
  def changelog_path
76
- File.join(@dir, Changelog::DEFAULT_FILE)
86
+ File.join(@dir, Manager::Changelog::DEFAULT_FILE)
77
87
  end
78
88
 
79
89
  def gemspec_path
@@ -1,57 +1,3 @@
1
- class Tumbler
2
- class Version
3
- include Runner
4
-
5
- attr_reader :file, :basefile, :field_names
6
-
7
- DEFAULT_FILE = 'VERSION'
8
- DEFAULT_FIELD = [:major, :minor, :tiny]
9
- INITIAL_VERSION = '0.0.0'
10
-
11
- def initialize(manager, &block)
12
- @manager = manager
13
- filename(DEFAULT_FILE)
14
- fields(DEFAULT_FIELD)
15
- instance_eval(&block) if block
16
- reload
17
- end
18
-
19
- def fields(f)
20
- @field_names = (f == :all ? @version.field_names : f)
21
- end
22
-
23
- def reload
24
- @version = Versionomy.parse(File.exist?(file) ? File.read(file).strip : '0.0.0')
25
- end
26
-
27
- def filename(file)
28
- @basefile = file
29
- @file = File.join(@manager.base, file)
30
- end
31
-
32
- def value
33
- @version
34
- end
35
-
36
- def to_s
37
- value.to_s
38
- end
39
-
40
- def bump(level)
41
- if @manager.noop
42
- @manager.dry "Bumping version to #{bump(level).to_s}"
43
- else
44
- File.open(file, 'w') {|f| f << @version.bump(level).to_s}
45
- reload
46
- end
47
- end
48
-
49
- def commit(from)
50
- sh "git commit #{@basefile} -m'Bumped version from #{from} to #{to_s}'"
51
- end
52
-
53
- def base
54
- @manager.base
55
- end
56
- end
1
+ module Tumbler
2
+ VERSION = '0.0.6'
57
3
  end
@@ -15,7 +15,7 @@ describe 'bin/tumbler' do
15
15
  it "should generate an app" do
16
16
  Dir.chdir(@target) {`bundle exec ruby #{@bin} test_gem`}
17
17
  $?.should == 0
18
- tumbler = Tumbler.new(File.join(@target, 'test_gem'))
18
+ tumbler = Tumbler.load(File.join(@target, 'test_gem'))
19
19
  tumbler.version.to_s.should == '0.0.0'
20
20
  tumbler.bundler.dependencies.first.name.should == 'tumbler'
21
21
  tumbler.bundler.dependencies.first.requirements_list.should == ['>= 0']
@@ -29,7 +29,7 @@ describe 'bin/tumbler' do
29
29
  end
30
30
 
31
31
  it "should do nothing on a normal existing tumbler app" do
32
- tumbler = Tumbler.new(File.join(@target, 'rails'))
32
+ tumbler = Tumbler.load(File.join(@target, 'rails'))
33
33
  version_file = File.read(tumbler.version.file)
34
34
  changelog_file = File.read(tumbler.changelog.file)
35
35
  gemfile_file = File.read(tumbler.gemfile_path)
@@ -43,7 +43,7 @@ describe 'bin/tumbler' do
43
43
  end
44
44
 
45
45
  it "should work from inside the directory" do
46
- tumbler = Tumbler.new(File.join(@target, 'rails'))
46
+ tumbler = Tumbler.load(File.join(@target, 'rails'))
47
47
  version_file = File.read(tumbler.version.file)
48
48
  changelog_file = File.read(tumbler.changelog.file)
49
49
  gemfile_file = File.read(tumbler.gemfile_path)
@@ -57,7 +57,7 @@ describe 'bin/tumbler' do
57
57
  end
58
58
 
59
59
  it "should not work if the directory and gemspec mismatch and you don't supply a name" do
60
- tumbler = Tumbler.new(File.join(@target, 'rails'))
60
+ tumbler = Tumbler.load(File.join(@target, 'rails'))
61
61
  FileUtils.mv("#{@target}/rails/rails.gemspec", "#{@target}/rails/notrails.gemspec")
62
62
  Dir.chdir(@target) {`bundle exec ruby #{@bin} rails -u`}
63
63
  $?.exitstatus.should == 1
@@ -1,6 +1,6 @@
1
1
  require 'spec/spec_helper'
2
2
 
3
- describe Tumbler::Changelog do
3
+ describe Tumbler::Manager::Changelog do
4
4
 
5
5
  after(:each) do
6
6
  $".delete "tumbler/gemspec.rb" # we need to delete this so each gemspec can be generated fresh
@@ -19,7 +19,7 @@ describe Tumbler::GemspecHelper do
19
19
  end
20
20
 
21
21
  it "should have files" do
22
- @helper.files.should == ["CHANGELOG", "Gemfile", "Rakefile", "Tumbler", "VERSION", "test.gemspec"]
22
+ @helper.files.should == ["CHANGELOG", "Gemfile", "Rakefile", "Tumbler", "lib/test/version.rb", "test.gemspec"]
23
23
  end
24
24
 
25
25
  it "should have a date" do
@@ -10,7 +10,7 @@ def create_app(name = 'test', opts = {})
10
10
  temp_dir(name) do |dir|
11
11
  temp_dir("remote-#{name}.git") do |remote_dir|
12
12
  Tumbler::Generate.app(dir, name, opts).write
13
- tumbler = Tumbler.new(dir)
13
+ tumbler = Tumbler::Manager.new(dir)
14
14
 
15
15
  Dir.chdir(remote_dir) { `git --bare init` }
16
16
 
@@ -29,7 +29,7 @@ end
29
29
  def create_bare_app(name, opts = {})
30
30
  dir = temp_dir(name)
31
31
  Tumbler::Generate.app(dir, name, opts).write
32
- tumbler = Tumbler.new(dir)
32
+ tumbler = Tumbler::Manager.new(dir)
33
33
  [dir, tumbler]
34
34
  end
35
35
 
@@ -16,9 +16,9 @@ describe Tumbler::Updater do
16
16
  it "should fetch the version number" do
17
17
  FakeWeb.allow_net_connect = false
18
18
  FakeWeb.register_uri(:get, "http://rubygems.org/api/v1/gems/rails.json", :body => '{ "name": "rails", "info": "Rails is a framework for building web-application using CGI, FCGI, mod_ruby, or WEBrick on top of either MySQL, PostgreSQL, SQLite, DB2, SQL Server, or Oracle with eRuby- or Builder-based templates.", "version": "2.3.5", "version_downloads": 2451, "authors": "David Heinemeier Hansson", "downloads": 134451, "project_uri": "http://rubygems.org/gems/rails", "gem_uri": "http://rubygems.org/gems/rails-2.3.5.gem", "dependencies": { "runtime": [ { "name": "activesupport", "requirements": ">= 2.3.5" } ], "development": [ ] }}')
19
- File.unlink("#{@target}/rails/VERSION")
19
+ File.unlink("#{@target}/rails/lib/rails/version.rb")
20
20
  Tumbler::Updater.new("#{@target}/rails", :name => 'rails').update
21
- File.read("#{@target}/rails/VERSION").should == '2.3.5'
21
+ File.read("#{@target}/rails/lib/rails/version.rb").should match(/2\.3\.5/)
22
22
  end
23
23
 
24
24
  it "should generate a CHANGELOG" do
@@ -51,4 +51,10 @@ describe Tumbler::Updater do
51
51
  File.read("#{@target}/rails/rails.gemspec").scan(/Tumbler::Gemspec.inject_dependencies/).size.should == 1
52
52
  end
53
53
 
54
+ it "should add a Tumbler config file if its not already there" do
55
+ File.unlink("#{@target}/rails/Tumbler")
56
+ Tumbler::Updater.new("#{@target}/rails", :name => 'rails').update
57
+ File.exist?("#{@target}/rails/Tumbler").should be_true
58
+ end
59
+
54
60
  end
@@ -9,6 +9,7 @@ describe 'Tumbler#version' do
9
9
 
10
10
  it "should bump the current version by minor" do
11
11
  create_app('test', :version => '0.1.2') { |tumbler|
12
+ puts "File.read(tumbler.version.file) #{File.read(tumbler.version.file)}"
12
13
  tumbler.bump_and_push(:minor)
13
14
  tumbler.version.to_s.should == '0.2.0'
14
15
  tumbler.tags.should include('0.2.0')
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tumbler
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Hull
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-16 00:00:00 -04:00
18
+ date: 2010-06-17 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -132,20 +132,26 @@ files:
132
132
  - README.rdoc
133
133
  - Rakefile
134
134
  - Tumbler
135
- - VERSION
136
135
  - bin/tumbler
136
+ - lib/template/Gemfile.erb
137
+ - lib/template/Rakefile
138
+ - lib/template/Tumbler.erb
139
+ - lib/template/generic.gemspec.erb
140
+ - lib/template/version.rb.erb
137
141
  - lib/tumbler.rb
138
- - lib/tumbler/changelog.rb
139
142
  - lib/tumbler/cli.rb
140
143
  - lib/tumbler/gem.rb
141
144
  - lib/tumbler/gemspec.rb
142
145
  - lib/tumbler/gemspec_helper.rb
143
146
  - lib/tumbler/generate.rb
147
+ - lib/tumbler/manager.rb
148
+ - lib/tumbler/manager/changelog.rb
149
+ - lib/tumbler/manager/version.rb
144
150
  - lib/tumbler/rake_tasks.rb
145
151
  - lib/tumbler/runner.rb
146
152
  - lib/tumbler/updater.rb
147
153
  - lib/tumbler/version.rb
148
- - spec/bin_bijou_spec.rb
154
+ - spec/bin_tumbler_spec.rb
149
155
  - spec/changelog_spec.rb
150
156
  - spec/gemspec_spec.rb
151
157
  - spec/generate_spec.rb
@@ -154,14 +160,9 @@ files:
154
160
  - spec/tasks_spec.rb
155
161
  - spec/updater_spec.rb
156
162
  - spec/version_spec.rb
157
- - template/Gemfile
158
- - template/Rakefile
159
- - template/generic.Tumbler.erb
160
- - template/generic.gemspec.erb
161
163
  - test1
162
164
  - thinking.txt
163
165
  - thinking2.txt
164
- - tumbler-0.0.1.gem
165
166
  - tumbler.gemspec
166
167
  has_rdoc: true
167
168
  homepage: http://github.com/joshbuddy/tumbler
@@ -198,7 +199,7 @@ signing_key:
198
199
  specification_version: 3
199
200
  summary: This is awesome.
200
201
  test_files:
201
- - spec/bin_bijou_spec.rb
202
+ - spec/bin_tumbler_spec.rb
202
203
  - spec/changelog_spec.rb
203
204
  - spec/gemspec_spec.rb
204
205
  - spec/generate_spec.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.4
@@ -1,62 +0,0 @@
1
- require 'tempfile'
2
- require 'fileutils'
3
-
4
- class Tumbler
5
- class Changelog
6
- include Runner
7
-
8
- DEFAULT_FILE = 'CHANGELOG'
9
-
10
- attr_reader :file
11
-
12
- def initialize(manager, &block)
13
- @manager = manager
14
- instance_eval(&block) if block
15
- end
16
-
17
- def filename(file)
18
- @basefile = file
19
- @file = File.join(@manager.base, file)
20
- end
21
-
22
- def write_version_header
23
- prepend "== #{@manager.version}\n\n"
24
- end
25
-
26
- def prepend(data)
27
- if @manager.noop
28
- @manager.dry "Prepending #{data} to #{@basefile}"
29
- else
30
- Tempfile.open('changelog') do |tmp|
31
- tmp.puts data
32
- File.open(@file) do |f|
33
- f.each do |line|
34
- tmp << line
35
- end
36
- end
37
- tmp.close
38
- FileUtils.copy(tmp.path, @file)
39
- File.unlink(tmp.path)
40
- end
41
- end
42
- end
43
-
44
- def update
45
- ensure_existence
46
- prepend("\n")
47
- prepend(@manager.latest_changes.inject('') { |changes, change| changes << "* #{change.summary} (#{change.author}, #{change.hash})\n" })
48
- end
49
-
50
- def ensure_existence
51
- File.open(@file, 'w') {|f| f << ''} unless File.exist?(@file)
52
- end
53
-
54
- def commit
55
- sh "git commit #{@basefile} -m'Updated changelog'"
56
- end
57
-
58
- def base
59
- @manager.base
60
- end
61
- end
62
- end
@@ -1,10 +0,0 @@
1
- source :rubygems
2
-
3
- # your dependencies go here
4
- # gem 'nokogiri'
5
-
6
- group :development do
7
- # your development dependencies go here
8
- # gem 'rake'
9
- # gem 'rspect'
10
- end
@@ -1,14 +0,0 @@
1
- gem_name <%=@name.inspect%>
2
-
3
- <% if @version %>
4
- use_version do
5
- filename 'VERSION'
6
- format 'standard'
7
- end
8
- <% end %>
9
-
10
- <% if @changelog %>
11
- use_changelog do
12
- filename <%=@changelog.inspect%>
13
- end
14
- <% end %>
Binary file