-
Notifications
You must be signed in to change notification settings - Fork 26
/
Rakefile
109 lines (89 loc) · 2.64 KB
/
Rakefile
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require "rake"
require "rake/clean"
NAME = 'forme'
VERS = lambda do
require File.expand_path("../lib/forme/version", __FILE__)
Forme.version
end
CLEAN.include ["#{NAME}-*.gem", "rdoc", "coverage", '**/*.rbc']
# Gem Packaging and Release
desc "Packages #{NAME}"
task :package=>[:clean] do |p|
sh %{gem build #{NAME}.gemspec}
end
desc "Upload #{NAME} gem to rubygems"
task :release=>[:package] do
sh %{gem push ./#{NAME}-#{VERS.call}.gem}
end
### RDoc
RDOC_DEFAULT_OPTS = ["--line-numbers", "--inline-source", '--title', 'Forme']
begin
gem 'rdoc', '= 3.12.2'
gem 'hanna-nouveau'
RDOC_DEFAULT_OPTS.concat(['-f', 'hanna'])
rescue Gem::LoadError
end
rdoc_task_class = begin
require "rdoc/task"
RDoc::Task
rescue LoadError
require "rake/rdoctask"
Rake::RDocTask
end
RDOC_OPTS = RDOC_DEFAULT_OPTS + ['--main', 'README.rdoc']
rdoc_task_class.new do |rdoc|
rdoc.rdoc_dir = "rdoc"
rdoc.options += RDOC_OPTS
rdoc.rdoc_files.add %w"README.rdoc CHANGELOG MIT-LICENSE lib/**/*.rb"
end
### Specs
begin
begin
# RSpec 1
require "spec/rake/spectask"
spec_class = Spec::Rake::SpecTask
spec_files_meth = :spec_files=
rescue LoadError
# RSpec 2
require "rspec/core/rake_task"
spec_class = RSpec::Core::RakeTask
spec_files_meth = :pattern=
end
spec = lambda do |name, files, d|
lib_dir = File.join(File.dirname(File.expand_path(__FILE__)), 'lib')
ENV['RUBYLIB'] ? (ENV['RUBYLIB'] += ":#{lib_dir}") : (ENV['RUBYLIB'] = lib_dir)
desc d
spec_class.new(name) do |t|
t.send spec_files_meth, files
t.spec_opts = ENV["#{NAME.upcase}_SPEC_OPTS"].split if ENV["#{NAME.upcase}_SPEC_OPTS"]
end
end
spec_with_cov = lambda do |name, files, d|
spec.call(name, files, d)
t = spec.call("#{name}_cov", files, "#{d} with coverage")
t.rcov = true
t.rcov_opts = File.read("spec/rcov.opts").split("\n") if File.file?("spec/rcov.opts")
end
task :default => [:spec]
spec_with_cov.call("spec", Dir["spec/*_spec.rb"], "Run specs")
rescue LoadError
task :default do
puts "Must install rspec to run the default task (which runs specs)"
end
end
### Other
desc "Print #{NAME} version"
task :version do
puts VERS.call
end
desc "Check syntax of all .rb files"
task :check_syntax do
Dir['**/*.rb'].each{|file| print `#{ENV['RUBY'] || :ruby} -c #{file} | fgrep -v "Syntax OK"`}
end
desc "Start an IRB shell using the extension"
task :irb do
require 'rbconfig'
ruby = ENV['RUBY'] || File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
irb = ENV['IRB'] || File.join(RbConfig::CONFIG['bindir'], File.basename(ruby).sub('ruby', 'irb'))
sh %{#{irb} -I lib -r forme}
end