Updated the README with more relevant data.
[stringray.git] / Rakefile.rb
blob06443623bd37ed242dd33bf23038dc71186fea68
1 LibName = "stringray"
2 ($:.unshift File.expand_path(File.join( File.dirname(__FILE__), 'lib' ))).uniq!
3 require LibName
4 Lib = StringRay
6 default_tasks = Array.new
8 # =======================
9 # = Gem packaging tasks =
10 # =======================
11 begin
12   require 'echoe'
13   
14   default_tasks << :'package:manifest' unless ENV['CI']
15   default_tasks << :'package:verify'
16   
17   task :install => :'package:install'
18   task :package => :'package:package'
19   task :manifest => :'package:manifest'
20   namespace :package do
21     Echoe.new(LibName, Lib::Version) do |g|
22       g.author = ['elliottcable']
23       g.email = ["#{LibName}@elliottcable.com"]
24       g.summary = 'Combining many of the benefits of Arrays and Strings, StringRay allows you to treat a String as an Array of words in many cases.'
25       g.url = 'http://github.com/elliottcable/' + LibName
26       g.runtime_dependencies = []
27       g.development_dependencies = ['echoe >= 3.0.2', 'rspec', 'rcov', 'yard']
28       g.manifest_name = '.manifest'
29       g.retain_gemspec = true
30       g.rakefile_name = 'Rakefile.rb'
31       g.ignore_pattern = /^\.git\/|^meta\/|\.gemspec/
32     end
33   
34     desc 'Tests packaged files to ensure they are all present'
35     task :verify => :package do
36       # An error message will be displayed if files are missing
37       if system %(ruby -e "require 'rubygems'; require 'pkg/#{LibName}-#{Lib::Version}/lib/#{LibName}'")
38         puts "\nThe library files are present."
39       end
40     end
41   end
42   
43 rescue LoadError => exception
44   raise exception unless exception.message =~ /(echoe)$/
45   desc '!! You need the `echoe` gem to package or install this project!'
46   task :package
47 end
49 # =======================
50 # = Spec/Coverage tasks =
51 # =======================
52 begin
53   require 'spec'
54   require 'rcov'
55   require 'spec/rake/spectask'
56   
57   default_tasks << :'coverage:run'
58   default_tasks << :'coverage:open' unless ENV['CI']
59   
60   task :coverage => :'coverage:run'
61   namespace :coverage do
62     Spec::Rake::SpecTask.new(:run) do |t|
63       t.spec_opts = ["--format", "specdoc"]
64       t.spec_opts << "--colour" unless ENV['CI']
65       t.spec_files = Dir[File.join('spec', '**', '*_spec.rb')].sort
66       t.libs = ['lib']
67       t.rcov = true
68       t.rcov_opts = ['--exclude-only', '".*"', '--include-file', '"^lib"',
69         '--sort', 'loc', '--sort-reverse',
70         '--comments', '--profile', '--text-report', '-w' ]
71       t.rcov_dir = File.join('meta', 'coverage')
72     end
73     
74     task :open do
75       system 'open ' + File.join('meta', 'coverage', 'index.html')
76     end if RUBY_PLATFORM =~ /darwin/
77   end
78   
79 rescue LoadError => exception
80   raise exception unless exception.message =~ /(rcov|spec)$/
81   desc '!! You need the `rcov` and `rspec` gems to run specs or coverage!'
82   task :coverage
83 end
85 # =======================
86 # = Documentation tasks =
87 # =======================
88 begin
89   require 'yard'
90   require 'yard/rake/yardoc_task'
91   
92   default_tasks << :'documentation:generate'
93   default_tasks << :'documentation:open' unless ENV['CI']
94   
95   task :documentation => :'documentation:generate'
96   namespace :documentation do
97     YARD::Rake::YardocTask.new :generate do |t|
98       t.files   = [File.join('lib', '**', '*.rb')]
99       t.options = ['--output-dir', File.join('meta', 'documentation'),
100                    '--readme', 'README.markdown']
101     end
102     
103     YARD::Rake::YardocTask.new :yardoc do |t|
104       t.files   = [File.join('lib', '**', '*.rb')]
105       t.options = ['--no-output',
106                    '--readme', 'README.markdown']
107     end
108     
109     task :open do
110       system 'open ' + File.join('meta', 'documentation', 'index.html')
111     end if RUBY_PLATFORM =~ /darwin/
112   end
113   
114 rescue LoadError => exception
115   raise exception unless exception.message =~ /(yard)$/
116   desc '!! You need the `yard` gem to generate documentation!'
117   task :documentation
120 # =================
121 # = Miscellaneous =
122 # =================
123 desc 'Removes all meta producs'
124 task :clobber do
125   `rm -rf #{File.expand_path(File.join( File.dirname(__FILE__), 'meta' ))} #{File.expand_path(File.join( File.dirname(__FILE__), 'pkg' ))}`
128 desc 'Run all default tasks'
129 task :default => default_tasks do
130   puts "** Successfully ran the following tasks:"
131   puts "** #{Rake.application.tasks.select {|t| t.name == 'default' }.first.prerequisites.join(', ')}"