forked from padrino/padrino-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgem_rake_helper.rb
73 lines (63 loc) · 1.84 KB
/
gem_rake_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require 'rubygems/specification' unless defined?(Gem::Specification)
require 'rake' unless defined?(Rake)
# Runs the sh command with sudo if the rake command is run with sudo
def sudo_sh(command)
command = `whoami`.strip! != "root" ? "sudo #{command}" : command
sh command
end
# Returns the gem specification object for a gem
def gemspec
@gemspec ||= begin
gem_name = File.basename(File.dirname(RAKE_ROOT))
file = File.expand_path("../#{gem_name}.gemspec", RAKE_ROOT)
::Gem::Specification.load(file)
end
end
# These are the uniform tasks used to build the individual padrino gems
#
# Use these by requiring them into the Rakefile in a gem
# RAKE_ROOT = __FILE__
# require 'rubygems'
# require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper')
#
# Most notable functions are:
# $ rake test # runs all tests
# $ rake package # packages the gem into the pkg folder
# $ rake install # installs the gem into system
# $ rake release # publishes gem to rubygems
desc "Validates the gemspec"
task :gemspec do
gemspec.validate
end
desc "Displays the current version"
task :version do
puts "Current version: #{gemspec.version}"
end
desc "Installs the gem locally"
task :install => :package do
sh "gem install pkg/#{gemspec.name}-#{gemspec.version}"
end
desc "Release the gem"
task :release => :package do
sh "gem push pkg/#{gemspec.name}-#{gemspec.version}.gem"
end
# rake test
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
# rake package
begin
require 'rake/gempackagetask'
rescue LoadError
task(:gem) { $stderr.puts '`gem install rake` to package gems' }
else
Rake::GemPackageTask.new(gemspec) do |pkg|
pkg.gem_spec = gemspec
end
task :gem => :gemspec
end
task :package => :gemspec
task :default => :test