-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
45 lines (36 loc) · 1.01 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
# encoding: utf-8
require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
desc 'Start IRB with all runtime dependencies loaded'
task :console, [:script] do |_t, args|
# TODO: move to a command
dirs = %w(ext lib).select { |dir| File.directory?(dir) }
original_load_path = $LOAD_PATH
_cmd = if File.exist?('Gemfile')
require 'bundler'
Bundler.setup(:default)
end
# add the project code directories
$LOAD_PATH.unshift(*dirs)
# clear ARGV so IRB is not confused
ARGV.clear
dirs.each { |dir|
Dir.foreach(dir) { |f|
require(f) if f =~ /\.rb/
}
}
require 'irb'
require 'irb/completion'
# set the optional script to run
IRB.conf[:SCRIPT] = args.script
IRB.start
# return the $LOAD_PATH to it's original state
$LOAD_PATH.reject! { |path| !original_load_path.include?(path) }
end