namelessjon-jeweler 0.6.2 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,53 +1,41 @@
1
1
  class Jeweler
2
- module Gemspec
3
- # Writes out the gemspec
4
- def write_gemspec
5
- self.refresh_version
6
- @gemspec.version = self.version
7
- @gemspec.date = Time.now
8
- File.open(gemspec_path, 'w') do |f|
9
- f.write @gemspec.to_ruby
10
- end
11
- puts "Generated: #{gemspec_path}"
12
- end
13
2
 
14
- # Validates the gemspec in an environment similar to how GitHub would build
15
- # it. See http://gist.github.com/16215
16
- def validate_gemspec
17
- begin
18
- parse_gemspec
19
- puts "#{gemspec_path} is valid."
20
- rescue Exception => e
21
- puts "#{gemspec_path} is invalid. See the backtrace for more details."
22
- raise
23
- end
24
- end
3
+ class GemSpecHelper
4
+
5
+ attr_accessor :spec, :base_dir
25
6
 
7
+ def initialize(spec, base_dir = nil)
8
+ self.spec = spec
9
+ self.base_dir = base_dir || ''
26
10
 
27
- def valid_gemspec?
11
+ yield spec if block_given?
12
+ end
13
+
14
+ def valid?
28
15
  begin
29
- parse_gemspec
16
+ parse
30
17
  true
31
- rescue Exception => e
18
+ rescue
32
19
  false
33
20
  end
34
21
  end
35
-
36
- def parse_gemspec(data = nil)
37
- data ||= File.read(gemspec_path)
38
- Thread.new { eval("$SAFE = 3\n#{data}", binding, gemspec_path) }.join
22
+
23
+ def write
24
+ File.open(path, 'w') do |f|
25
+ f.write @spec.to_ruby
26
+ end
39
27
  end
40
28
 
41
- def unsafe_parse_gemspec(data = nil)
42
- data ||= File.read(gemspec_path)
43
- eval(data, binding, gemspec_path)
29
+ def path
30
+ denormalized_path = File.join(@base_dir, "#{@spec.name}.gemspec")
31
+ absolute_path = File.expand_path(denormalized_path)
32
+ absolute_path.gsub(Dir.getwd + File::SEPARATOR, '')
44
33
  end
45
34
 
46
- protected
47
- def gemspec_path
48
- denormalized_path = File.join(@base_dir, "#{@gemspec.name}.gemspec")
49
- absolute_path = File.expand_path(denormalized_path)
50
- absolute_path.gsub(Dir.getwd + File::SEPARATOR, '')
35
+ def parse
36
+ data = File.read(path)
37
+ Thread.new { eval("$SAFE = 3\n#{data}", binding, path) }.join
51
38
  end
39
+
52
40
  end
53
41
  end
@@ -52,6 +52,8 @@ class Jeweler
52
52
  if should_create_repo
53
53
  create_and_push_repo
54
54
  puts "Jeweler has pushed your repo to #{github_url}"
55
+ enable_gem_for_repo
56
+ puts "Jeweler has enabled gem building for your repo"
55
57
  end
56
58
  end
57
59
 
@@ -164,6 +166,17 @@ class Jeweler
164
166
  @repo.push('origin')
165
167
  end
166
168
 
169
+ def enable_gem_for_repo
170
+ url = "https://github.com/#{github_username}/#{github_repo_name}/update"
171
+ `curl -F 'login=#{github_username}' -F 'token=#{github_token}' -F 'field=repository_rubygem' -F 'value=1' #{url} 2>/dev/null`
172
+ # FIXME use NET::HTTP instead of curl
173
+ #Net::HTTP.post_form URI.parse(url),
174
+ #'login' => github_username,
175
+ #'token' => github_token,
176
+ #'field' => 'repository_rubygem',
177
+ #'value' => '1'
178
+ end
179
+
167
180
  def read_git_config
168
181
  # we could just use Git::Base's .config, but that relies on a repo being around already
169
182
  # ... which we don't have yet, since this is part of a sanity check
data/lib/jeweler/tasks.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rake'
2
2
  require 'rake/tasklib'
3
- require 'rubygems/builder'
4
3
 
5
4
  class Jeweler
6
5
  class Tasks < ::Rake::TaskLib
@@ -16,18 +15,32 @@ class Jeweler
16
15
  end
17
16
 
18
17
  private
19
- def ensure_version_yml(&block)
20
- unless File.exists? 'VERSION.yml'
21
- @jeweler.write_version(ENV['MAJOR'], ENV['MINOR'], ENV['PATCH'])
18
+ def define
19
+ desc "Setup initial version of 0.0.0"
20
+ file "VERSION.yml" do
21
+ @jeweler.write_version 0, 0, 0, :commit => false
22
+ $stdout.puts "Created VERSION.yml: 0.0.0"
22
23
  end
23
- block.call if block
24
- end
25
24
 
26
- def define
27
- desc "Generate a gem"
28
- task :gem => :'gemspec:validate' do
29
- gemspec = @jeweler.unsafe_parse_gemspec
30
- Gem::Builder.new(gemspec).build
25
+ desc "Build gem"
26
+ task :build => :'gem:build'
27
+
28
+ desc "Build gem"
29
+ task :gem => :'gem:build'
30
+
31
+ desc "Install gem using sudo"
32
+ task :install => :'gem:install'
33
+
34
+ namespace :gem do
35
+ desc "Install gem using sudo"
36
+ task :install => :build do
37
+ @jeweler.install_gem
38
+ end
39
+
40
+ desc "Build gem"
41
+ task :build => :'gemspec:validate' do
42
+ @jeweler.build_gem
43
+ end
31
44
  end
32
45
 
33
46
  desc "Generate and validates gemspec"
@@ -35,15 +48,13 @@ class Jeweler
35
48
 
36
49
  namespace :gemspec do
37
50
  desc "Validates the gemspec"
38
- task :validate do
51
+ task :validate => 'VERSION.yml' do
39
52
  @jeweler.validate_gemspec
40
53
  end
41
54
 
42
- desc "Generates the gemspec"
43
- task :generate do
44
- ensure_version_yml do
45
- @jeweler.write_gemspec
46
- end
55
+ desc "Generates the gemspec, using version from VERSION.yml"
56
+ task :generate => 'VERSION.yml' do
57
+ @jeweler.write_gemspec
47
58
  end
48
59
  end
49
60
 
@@ -51,38 +62,38 @@ class Jeweler
51
62
  task :version => 'version:display'
52
63
 
53
64
  namespace :version do
54
- desc "Creates an initial version file. Respects the following environment variables, or defaults to 0: MAJOR, MINOR, PATCH"
65
+ desc "Setup initial version of 0.0.0"
66
+ task :setup => "VERSION.yml"
67
+
68
+ desc "Writes out an explicit version. Respects the following environment variables, or defaults to 0: MAJOR, MINOR, PATCH"
55
69
  task :write do
56
- @jeweler.write_version(ENV['MAJOR'], ENV['MINOR'], ENV['PATCH'])
70
+ major, minor, patch = ENV['MAJOR'].to_i, ENV['MINOR'].to_i, ENV['PATCH'].to_i
71
+ @jeweler.write_version(major, minor, patch, :announce => false, :commit => false)
72
+ $stdout.puts "Updated version: #{@jeweler.version}"
57
73
  end
58
74
 
59
75
  desc "Displays the current version"
60
- task :display do
61
- ensure_version_yml do
62
- puts "Current version: #{@jeweler.version}"
63
- end
76
+ task :display => :setup do
77
+ $stdout.puts "Current version: #{@jeweler.version}"
64
78
  end
65
79
 
66
80
  namespace :bump do
67
81
  desc "Bump the gemspec by a major version."
68
- task :major => 'version:display' do
69
- ensure_version_yml do
70
- @jeweler.bump_major_version
71
- end
82
+ task :major => ['VERSION.yml', :display] do
83
+ @jeweler.bump_major_version
84
+ $stdout.puts "Updated version: #{@jeweler.version}"
72
85
  end
73
86
 
74
87
  desc "Bump the gemspec by a minor version."
75
- task :minor => 'version:display' do
76
- ensure_version_yml do
77
- @jeweler.bump_minor_version
78
- end
88
+ task :minor => ['VERSION.yml', 'version:display'] do
89
+ @jeweler.bump_minor_version
90
+ $stdout.puts "Updated version: #{@jeweler.version}"
79
91
  end
80
92
 
81
93
  desc "Bump the gemspec by a patch version."
82
- task :patch => 'version:display' do
83
- ensure_version_yml do
84
- @jeweler.bump_patch_version
85
- end
94
+ task :patch => ['VERSION.yml', 'version:display'] do
95
+ @jeweler.bump_patch_version
96
+ $stdout.puts "Updated version: #{@jeweler.version}"
86
97
  end
87
98
  end
88
99
  end
@@ -0,0 +1,81 @@
1
+ class Jeweler
2
+ class Version
3
+ attr_accessor :base_dir
4
+ attr_reader :major, :minor, :patch
5
+
6
+ def initialize(base_dir)
7
+ self.base_dir = base_dir
8
+
9
+ if File.exists?(yaml_path)
10
+ parse_yaml
11
+ end
12
+ end
13
+
14
+ def bump_major
15
+ @major += 1
16
+ @minor = 0
17
+ @patch = 0
18
+ end
19
+
20
+ def bump_minor
21
+ @minor += 1
22
+ @patch = 0
23
+ end
24
+
25
+ def bump_patch
26
+ @patch += 1
27
+ end
28
+
29
+ def update_to(major, minor, patch)
30
+ @major = major
31
+ @minor = minor
32
+ @patch = patch
33
+ end
34
+
35
+ def write
36
+ File.open(yaml_path, 'w+') do |f|
37
+ YAML.dump(self.to_hash, f)
38
+ end
39
+ end
40
+
41
+ def to_s
42
+ "#{major}.#{minor}.#{patch}"
43
+ end
44
+
45
+ def to_hash
46
+ {
47
+ :major => major,
48
+ :minor => minor,
49
+ :patch => patch
50
+ }
51
+ end
52
+
53
+ def refresh
54
+ parse_yaml
55
+ end
56
+
57
+ def yaml_path
58
+ denormalized_path = File.join(@base_dir, 'VERSION.yml')
59
+ absolute_path = File.expand_path(denormalized_path)
60
+ absolute_path.gsub(Dir.getwd + File::SEPARATOR, '')
61
+ end
62
+
63
+ protected
64
+
65
+ def parse_yaml
66
+ yaml = read_yaml
67
+ @major = (yaml['major'] || yaml[:major]).to_i
68
+ @minor = (yaml['minor'] || yaml[:minor]).to_i
69
+ @patch = (yaml['patch'] || yaml[:patch]).to_i
70
+ end
71
+
72
+ def read_yaml
73
+ if File.exists?(yaml_path)
74
+ YAML.load_file(yaml_path)
75
+ else
76
+ raise VersionYmlError, "#{yaml_path} does not exist!"
77
+ end
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class GemspecTest < Test::Unit::TestCase
4
+ context "A Jeweler::GemSpec, given a gemspec" do
5
+ setup do
6
+ @spec = build_spec
7
+ @helper = Jeweler::GemSpecHelper.new(@spec, File.dirname(__FILE__))
8
+ end
9
+
10
+ should 'have sane gemspec path' do
11
+ assert_equal "test/#{@spec.name}.gemspec", @helper.path
12
+ end
13
+ end
14
+
15
+ context "Jeweler::GemSpec#write" do
16
+ setup do
17
+ @spec = build_spec
18
+ @helper = Jeweler::GemSpecHelper.new(@spec)
19
+ FileUtils.rm_f(@helper.path)
20
+
21
+ @helper.write
22
+ end
23
+
24
+ should "create gemspec file" do
25
+ assert File.exists?(@helper.path)
26
+ end
27
+
28
+ should "make valid spec" do
29
+ assert @helper.valid?
30
+ end
31
+ end
32
+ end
@@ -68,7 +68,7 @@ class JewelerGeneratorInitializerTest < Test::Unit::TestCase
68
68
  end
69
69
  end
70
70
 
71
- context "without github username set" do
71
+ context "without github token set" do
72
72
  setup do
73
73
  Jeweler::Generator.any_instance.stubs(:read_git_config).
74
74
  returns({'user.email' => 'bar@example.com', 'user.name' => 'foo', 'github.user' => 'technicalpickles'})
@@ -143,4 +143,4 @@ class JewelerGeneratorInitializerTest < Test::Unit::TestCase
143
143
  end
144
144
  end
145
145
  end
146
- end
146
+ end
data/test/jeweler_test.rb CHANGED
@@ -12,18 +12,6 @@ class JewelerTest < Test::Unit::TestCase
12
12
  FileUtils.rm_rf("#{File.dirname(__FILE__)}/tmp")
13
13
  end
14
14
 
15
- def build_spec
16
- Gem::Specification.new do |s|
17
- s.name = "bar"
18
- s.summary = "Simple and opinionated helper for creating Rubygem projects on GitHub"
19
- s.email = "josh@technicalpickles.com"
20
- s.homepage = "http://github.com/technicalpickles/jeweler"
21
- s.description = "Simple and opinionated helper for creating Rubygem projects on GitHub"
22
- s.authors = ["Josh Nichols", "Dan Croak"]
23
- s.files = FileList["[A-Z]*", "{generators,lib,test}/**/*"]
24
- end
25
- end
26
-
27
15
  context "A jeweler without a VERSION.yml" do
28
16
  setup do
29
17
  FileUtils.mkdir_p(tmp_dir)
@@ -31,7 +19,7 @@ class JewelerTest < Test::Unit::TestCase
31
19
  end
32
20
 
33
21
  should "not have VERSION.yml" do
34
- assert ! File.exists?(File.join(tmp_dir, 'bar.gemspec'))
22
+ assert ! File.exists?(File.join(tmp_dir, 'VERSION.yml'))
35
23
  end
36
24
  end
37
25
 
@@ -39,7 +27,7 @@ class JewelerTest < Test::Unit::TestCase
39
27
  context "A Jeweler with a VERSION.yml" do
40
28
  setup do
41
29
  FileUtils.cp_r(fixture_dir, tmp_dir)
42
-
30
+
43
31
  @jeweler = Jeweler.new(build_spec, tmp_dir)
44
32
  end
45
33
 
@@ -71,6 +59,35 @@ class JewelerTest < Test::Unit::TestCase
71
59
  should_bump_version 2, 0, 0
72
60
  end
73
61
 
62
+ should "should find files" do
63
+ assert ! @jeweler.gemspec.files.empty?
64
+ end
65
+
66
+ context "with standard 'files' specified" do
67
+ setup do
68
+ @alt_jeweler = Jeweler.new(build_spec("[A-Z]*.*", "{bin,generators,lib,test,spec}/**/*"), tmp_dir)
69
+ end
70
+
71
+ should "have the same files as when no 'files' are specified" do
72
+ assert_equal @jeweler.gemspec.files, @alt_jeweler.gemspec.files
73
+ end
74
+ end
75
+
76
+ context "gemsepc's rdoc" do
77
+ should 'have be enabled' do
78
+ assert @jeweler.gemspec.has_rdoc
79
+ end
80
+
81
+ should 'do inline source' do
82
+ assert @jeweler.gemspec.rdoc_options.include?('--inline-source')
83
+ end
84
+
85
+ should 'be utf-8' do
86
+ assert @jeweler.gemspec.rdoc_options.include?('--charset=UTF-8')
87
+ end
88
+
89
+ end
90
+
74
91
  context "writing the gemspec" do
75
92
  setup do
76
93
  @output = catch_out { @jeweler.write_gemspec }
@@ -30,9 +30,6 @@ class Test::Unit::TestCase
30
30
  should_have_minor_version minor
31
31
  should_have_patch_version patch
32
32
  should_be_version version
33
- should "output the new version, #{version}" do
34
- assert_match version, @output
35
- end
36
33
  end
37
34
  end
38
35
  end
data/test/tasks_test.rb CHANGED
@@ -22,6 +22,8 @@ class TasksTest < Test::Unit::TestCase
22
22
  end
23
23
 
24
24
  should 'define tasks' do
25
+ assert Task.task_defined?(:build)
26
+ assert Task.task_defined?(:install)
25
27
  assert Task.task_defined?(:gemspec)
26
28
  assert Task.task_defined?(:'gemspec:validate')
27
29
  assert Task.task_defined?(:'gemspec:generate')