technicalpickles-jeweler 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,13 +1,52 @@
1
- # Create a directory and git repo
1
+ # Jeweler: Let us craft you the perfect gem
2
+
3
+ Rubygems are the awesome way of distributing your code to others. GitHub is the awesome way of managing the source code of your project. GitHub can even generate a Rubygem if you include a gemspec.
4
+
5
+ Trouble is when developing your Rubygems on GitHub, you generally do one of the following:
6
+
7
+ * Manage the gemspec by hand
8
+ * ... why bother doing something by hand when you can automate it?
9
+ * Write your own rake stuff to manage the gemspec, and deal with managing the version somehow
10
+ * ... why keep reinventing the wheel?
11
+ * use hoe or echoe for generating the gemspec
12
+ * ... why use utilities made for the days before GitHub existed?
13
+ * ... why have extra stuff you aren't going to use?
14
+
15
+ Jeweler was created with some simple goals:
16
+
17
+ * The only configuration should be providing a Gem::Specification to Jeweler
18
+ * Version bumping should only be one command away
19
+ * Authoritative version information should stored in one place, a Version module in your project
20
+ * Jeweler should only concern itself with versioning and gems (and one day, git)
21
+ * Your Rakefile should be usable when Jeweler isn't installed (you just wouldn't be able to version bump or generate a gemspec)
22
+ * Jeweler should use Jeweler. Oh the meta!
23
+
24
+ ## Use Jeweler in a new project
25
+
26
+ We'll use Jeweler as an example for creating a new project.
27
+
28
+ ### Install it
29
+
30
+ Run the following if you haven't already:
31
+
32
+ gem sources -a http://gems.github.com
33
+
34
+ Install the gem:
35
+
36
+ sudo gem install technicalpickles-jeweler
37
+
38
+ ### Create a directory and git repo
2
39
 
3
40
  $ mkdir jeweler
41
+ $ cd jeweler
4
42
  $ git init
5
43
 
6
- # Create a Rakefile:
44
+ ### Create a Rakefile:
7
45
 
8
46
  require 'rake'
9
47
 
10
48
  begin
49
+ require 'rubygems'
11
50
  require 'jeweler'
12
51
  Jeweler.gemspec = Gem::Specification.new do |s|
13
52
  s.name = "jeweler"
@@ -22,14 +61,13 @@
22
61
  puts "Jeweler not available. Try installing technicalpickles-jeweler."
23
62
  end
24
63
 
64
+ Note, we don't include 'date', or 'version'. Jeweler handles filing these in when it needs them.
25
65
 
26
- Note, we don't include 'date', or 'version'. Jeweler takes care of that.
27
-
28
- If you don't specify `s.files`, it will use `s.files = FileList["[A-Z]*", "{generators,lib,test,spec}/**/*"]`
66
+ If you don't specify `s.files`, it will use `s.files = FileList["[A-Z]*", "{generators,lib,test,spec}/**/*"]`.
29
67
 
30
- For now, `s.name` should be lower-cased and underscored, without hyphens. That's because Jeweler camelizes and constantizes this value internally. For example, `ruby-debug` would be camelized/constanized to `Ruby-debug`, which isn't valid.
68
+ For now, `s.name` should be lower-cased and underscored, without hyphens. That's because Jeweler camelizes and constantizes this value internally. For example, `ruby-debug` would be camelized/constanized to `Ruby-debug`, which isn't a valid constant. Use `ruby_debug` instead (for now).
31
69
 
32
- # Create a version file
70
+ ### Create a version file
33
71
 
34
72
  Stick it in `lib/(spec_name_here)/version.rb`, and start it out at some version, like 0.0.0:
35
73
 
@@ -51,40 +89,44 @@ OR
51
89
  end
52
90
  end
53
91
 
54
- Which you use depends on how you want to organize your gem. If you have a top-level class, like Jeweler, use the first. If you have a top level module, like Clearance, use the latter.
92
+ Which you use depends on how you want to organize your gem. If you have a top-level class, like Jeweler, use the first. If you have a top level module, like ActiveRecord, use the latter.
55
93
 
56
- # Generate the first gemspec
94
+ ### Generate the gemspec
57
95
 
58
96
  $ rake gemspec
97
+
98
+ This also validates that the gemspec should work on GitHub.
59
99
 
60
- # Commit it
100
+ ### Commit it already
61
101
 
62
102
  $ git add .
63
- $ git commit -a -m "First commit yo"
103
+ $ git commit -a -m "First commit, yo."
64
104
 
65
- # Make a github repository
105
+ ### Make a github repository
66
106
 
67
- Wander to http://github.com/repositories/new and follow the instructions to get it pushed
107
+ Wander to http://github.com/repositories/new and follow the instructions to get it pushed.
68
108
 
69
- # Enable Rubygem building on the repository
109
+ ### Enable RubyGem building on the repository
70
110
 
71
111
  Go to your project's edit page and check the 'RubyGem' box.
72
112
 
73
- # Go do something awesome
113
+ ### Implement something awesome
74
114
 
75
- I'll let you figure that out
115
+ I'll let you figure that out on your own.
76
116
 
77
- # Bump the version
117
+ ### Bump the version
78
118
 
79
- You have a few rake tasks for automating the version bumping:
119
+ You have a few rake tasks for doing the version bump:
80
120
 
81
- $ rake version:bump:patch
82
- $ rake version:bump:minor
83
- $ rake version:bump:major
84
-
85
- This will automatically regenerate your gemspec.
121
+ $ rake version:bump:patch # 1.5.1 -> 1.5.2
122
+ $ rake version:bump:minor # 1.5.1 -> 1.6.0
123
+ $ rake version:bump:major # 1.5.1 -> 2.0.0
124
+
125
+ After that, commit and push it:
126
+
127
+ $ git commit -a -m "Version bump, yo."
128
+ $ git push origin master
86
129
 
87
- Just commit and push it afterwards:
130
+ ### Play the waiting game
88
131
 
89
- $ git commit -a -m "Version bump yo"
90
- $ git push origin master
132
+ Wander over to [Has My Gem Built Yet](http://hasmygembuiltyet.org/) to play the waiting game.
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
+ require 'rake/rdoctask'
3
4
 
4
5
  $:.unshift('lib')
5
6
 
@@ -23,6 +24,15 @@ Rake::TestTask.new do |t|
23
24
  t.pattern = 'test/**/*_test.rb'
24
25
  t.verbose = false
25
26
  end
27
+
28
+ desc 'Generate documentation for the safety_valve plugin.'
29
+ Rake::RDocTask.new(:rdoc) do |rdoc|
30
+ rdoc.rdoc_dir = 'rdoc'
31
+ rdoc.title = 'Jeweler'
32
+ rdoc.options << '--line-numbers' << '--inline-source'
33
+ rdoc.rdoc_files.include('README.markdown')
34
+ rdoc.rdoc_files.include('lib/**/*.rb')
35
+ end
26
36
 
27
37
  desc "Run the test suite"
28
38
  task :default => :test
data/TODO CHANGED
@@ -2,5 +2,7 @@
2
2
  * ruby-debug -> Ruby::Debug
3
3
  * safety_valve -> SafetyValve
4
4
  * Generator for making new Jeweler projects
5
+ * Rails generator for making a plugin that's Jeweler enabled
5
6
  * Git tagging/branching
6
- * Release task
7
+ * Make sure everything is pushed/committed before bumping (controlled by a Jeweler.strict perhaps)
8
+ * Have version:bump:xxx do a commit with an appropriate message
@@ -1,5 +1,8 @@
1
1
  class Jeweler
2
2
  module Bumping
3
+ # Bumps the patch version.
4
+ #
5
+ # 1.5.1 -> 1.5.2
3
6
  def bump_patch_version()
4
7
  patch = self.patch_version + 1
5
8
 
@@ -7,6 +10,9 @@ class Jeweler
7
10
  write_gemspec
8
11
  end
9
12
 
13
+ # Bumps the minor version.
14
+ #
15
+ # 1.5.1 -> 1.6.0
10
16
  def bump_minor_version()
11
17
  minor = minor_version + 1
12
18
 
@@ -14,6 +20,9 @@ class Jeweler
14
20
  write_gemspec
15
21
  end
16
22
 
23
+ # Bumps the major version.
24
+ #
25
+ # 1.5.1 -> 2.0.0
17
26
  def bump_major_version()
18
27
  major = major_version + 1
19
28
 
@@ -21,26 +30,29 @@ class Jeweler
21
30
  write_gemspec
22
31
  end
23
32
 
33
+ # Bumps the version, to the specific major/minor/patch version, writing out the appropriate version.rb, and then reloads it.
24
34
  def bump_version(major, minor, patch)
25
35
  main_module_or_class = constantize(main_module_name)
26
36
  keyword = top_level_keyword()
27
37
 
28
38
  File.open(version_module_path, 'w') do |file|
29
39
  file.write <<-END
30
- #{keyword} #{main_module_name}
31
- module Version
32
- MAJOR = #{major}
33
- MINOR = #{minor}
34
- PATCH = #{patch}
35
- end
40
+ #{keyword} #{main_module_name}
41
+ module Version
42
+ MAJOR = #{major}
43
+ MINOR = #{minor}
44
+ PATCH = #{patch}
36
45
  end
37
- END
46
+ end
47
+ END
38
48
  end
39
49
  @gemspec.version = "#{major}.#{minor}.#{patch}"
40
50
  refresh_version
41
51
  end
42
52
 
43
53
  protected
54
+ # Tries to figure out the Ruby keyword of what is containing the Version
55
+ # module. This should be 'module' or 'class', and is used for rewriting the version.rb.
44
56
  def top_level_keyword
45
57
  main_module_or_class = constantize(main_module_name)
46
58
  case main_module_or_class
@@ -0,0 +1,5 @@
1
+ class Jeweler
2
+ # Gemspec related error
3
+ class GemspecError < StandardError
4
+ end
5
+ end
@@ -1,16 +1,40 @@
1
1
  class Jeweler
2
2
  module Gemspec
3
+ # Generates a date for stuffing in the gemspec
3
4
  def date
4
5
  date = DateTime.now
5
6
  "#{date.year}-#{date.month}-#{date.day}"
6
7
  end
7
8
 
8
9
 
10
+ # Writes out the gemspec
9
11
  def write_gemspec
10
12
  @gemspec.date = self.date
11
13
  File.open(gemspec_path, 'w') do |f|
12
14
  f.write @gemspec.to_ruby
13
15
  end
16
+ puts "Generated #{gemspec_path}."
17
+ end
18
+
19
+ # Validates the gemspec in an environment similar to how GitHub would build
20
+ # it. See http://gist.github.com/16215
21
+ def validate_gemspec
22
+ begin
23
+ # Snippet borrowed from http://gist.github.com/16215
24
+ data = File.read(gemspec_path)
25
+
26
+ spec = nil
27
+ if data !~ %r{!ruby/object:Gem::Specification}
28
+ Thread.new { spec = eval("$SAFE = 3\n#{data}", binding, gemspec_path) }.join
29
+ else
30
+ spec = YAML.load(data)
31
+ end
32
+
33
+ puts "#{gemspec_path} is valid."
34
+ rescue Exception => e
35
+ puts "#{gemspec_path} is invalid. See the backtrace for more details."
36
+ raise
37
+ end
14
38
  end
15
39
 
16
40
  protected
@@ -5,10 +5,14 @@ class Jeweler
5
5
  end
6
6
 
7
7
  module ClassMethods
8
- def gemspec=(gemspec)
8
+ # Gives Jeweler a gem to craft. This is really just a convience method for making the Rake usage nicer.
9
+ # In reality, this creates a new Jeweler, and assigns that to the singleton instance.
10
+ def craft(gemspec)
9
11
  @@instance = new(gemspec)
10
12
  end
13
+ alias_method :gemspec=, :craft
11
14
 
15
+ # Gets the current Jeweler. Typically only the Jeweler Rake tasks would use this.
12
16
  def instance
13
17
  @@instance
14
18
  end
data/lib/jeweler/tasks.rb CHANGED
@@ -1,6 +1,16 @@
1
- desc "Generate a gemspec file for GitHub"
2
- task :gemspec do
3
- Jeweler.instance.write_gemspec
1
+ desc "Generate and validates gemspec"
2
+ task :gemspec => ['gemspec:generate', 'gemspec:validate']
3
+
4
+ namespace :gemspec do
5
+ desc "Validates the gemspec"
6
+ task :validate do
7
+ Jeweler.instance.validate_gemspec
8
+ end
9
+
10
+ desc "Generates the gemspec"
11
+ task :generate do
12
+ Jeweler.instance.write_gemspec
13
+ end
4
14
  end
5
15
 
6
16
  desc "Displays the current version"
@@ -10,11 +20,11 @@ end
10
20
 
11
21
  namespace :version do
12
22
  namespace :bump do
13
- desc "Bump the gemspec a major version."
23
+ desc "Bump the gemspec by a major version."
14
24
  task :major do
15
25
  jeweler = Jeweler.instance
16
26
 
17
- major = jeweler.major_version + 1
27
+ jeweler.bump_major_version
18
28
 
19
29
  jeweler.bump_version(major, 0, 0)
20
30
  jeweler.write_gemspec
@@ -22,14 +32,14 @@ namespace :version do
22
32
  puts "Version bumped to #{jeweler.version}"
23
33
  end
24
34
 
25
- desc "Bump the gemspec a minor version."
35
+ desc "Bump the gemspec by a minor version."
26
36
  task :minor do
27
37
  jeweler = Jeweler.instance
28
38
  jeweler.bump_minor_version
29
39
  puts "Version bumped to #{jeweler.version}"
30
40
  end
31
41
 
32
- desc "Bump the gemspec a patch version."
42
+ desc "Bump the gemspec by a patch version."
33
43
  task :patch do
34
44
  jeweler = Jeweler.instance
35
45
  jeweler.bump_patch_version
@@ -1,7 +1,7 @@
1
- class Jeweler
2
- module Version
3
- MAJOR = 0
4
- MINOR = 0
5
- PATCH = 6
6
- end
1
+ class Jeweler
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ PATCH = 7
7
6
  end
7
+ end
@@ -1,17 +1,24 @@
1
1
  class Jeweler
2
2
  module Versioning
3
+ # Major version, as defined by the gemspec's Version module.
4
+ # For 1.5.3, this would return 1.
3
5
  def major_version
4
6
  version_module.const_get(:MAJOR)
5
7
  end
6
8
 
9
+ # Minor version, as defined by the gemspec's Version module.
10
+ # For 1.5.3, this would return 5.
7
11
  def minor_version
8
12
  version_module.const_get(:MINOR)
9
13
  end
10
14
 
15
+ # Patch version, as defined by the gemspec's Version module.
16
+ # For 1.5.3, this would return 5.
11
17
  def patch_version
12
18
  version_module.const_get(:PATCH)
13
19
  end
14
20
 
21
+ # Human readable version, which is used in the gemspec.
15
22
  def version
16
23
  "#{major_version}.#{minor_version}.#{patch_version}"
17
24
  end
@@ -25,12 +32,13 @@ class Jeweler
25
32
  constantize("#{main_module_name}::Version")
26
33
  end
27
34
 
35
+ #
28
36
  def refresh_version
29
- # Remove the constants, so we can reload the version_module
30
37
  undefine_versions()
31
38
  load_version()
32
39
  end
33
40
 
41
+ # Undefines version constants, so we can +load+ the version.rb again.
34
42
  def undefine_versions
35
43
  version_module.module_eval do
36
44
  remove_const(:MAJOR) if const_defined?(:MAJOR)
@@ -40,7 +48,7 @@ class Jeweler
40
48
  end
41
49
 
42
50
  def load_version
43
- load version_module_path
51
+ load(version_module_path)
44
52
  end
45
53
  end
46
54
  end
data/lib/jeweler.rb CHANGED
@@ -4,10 +4,12 @@ require 'jeweler/bumping'
4
4
  require 'jeweler/versioning'
5
5
  require 'jeweler/singleton'
6
6
  require 'jeweler/gemspec'
7
+ require 'jeweler/errors'
7
8
 
8
9
  require 'jeweler/tasks' if defined?(Rake)
9
10
  require 'jeweler/active_support' # Adds the stolen camelize and constantize
10
11
 
12
+ # A Jeweler helps you craft the perfect Rubygem. Give him a gemspec, and he takes care of the rest.
11
13
  class Jeweler
12
14
  include Jeweler::Singleton
13
15
  include Jeweler::Bumping
@@ -18,6 +20,7 @@ class Jeweler
18
20
  attr_accessor :base_dir
19
21
 
20
22
  def initialize(gemspec, base_dir = '.')
23
+ raise(GemspecError, "Can't create a Jeweler with a nil gemspec") if gemspec.nil?
21
24
  @gemspec = gemspec
22
25
  @base_dir = base_dir
23
26
 
data/test/jeweler_test.rb CHANGED
@@ -56,7 +56,7 @@ end
56
56
  end
57
57
  end
58
58
 
59
- context 'A gem, with top level module,' do
59
+ context 'A jeweler (with a gemspec with top level module)' do
60
60
  setup do
61
61
  write_version_file('foo', 'module', 'Foo', 0, 1, 0)
62
62
  @spec = Gem::Specification.new do |s|
@@ -129,7 +129,7 @@ end
129
129
 
130
130
  end
131
131
 
132
- context "A gem, with top level class," do
132
+ context "A Jeweler (with a gemspec with top level class)" do
133
133
  setup do
134
134
  write_version_file('bar', 'class', 'Bar', 1, 5, 2)
135
135
 
@@ -171,4 +171,10 @@ end
171
171
  end
172
172
  end
173
173
 
174
+ should "raise an exception when created with a nil gemspec" do
175
+ assert_raises Jeweler::GemspecError do
176
+ @jeweler = Jeweler.new(nil, File.dirname(__FILE__))
177
+ end
178
+ end
179
+
174
180
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: technicalpickles-jeweler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Nichols
@@ -29,6 +29,7 @@ files:
29
29
  - lib/jeweler
30
30
  - lib/jeweler/active_support.rb
31
31
  - lib/jeweler/bumping.rb
32
+ - lib/jeweler/errors.rb
32
33
  - lib/jeweler/gemspec.rb
33
34
  - lib/jeweler/singleton.rb
34
35
  - lib/jeweler/tasks.rb