spin 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/spin +46 -24
- metadata +4 -4
data/bin/spin
CHANGED
@@ -13,15 +13,14 @@ require 'digest/md5'
|
|
13
13
|
# So we can tell users how much time they're saving by preloading their
|
14
14
|
# environment.
|
15
15
|
require 'benchmark'
|
16
|
+
require 'optparse'
|
16
17
|
|
17
|
-
def usage
|
18
|
-
|
18
|
+
def usage
|
19
|
+
<<-USAGE
|
19
20
|
Usage: spin serve
|
20
|
-
spin push <file>...
|
21
|
+
spin push <file> <file>...
|
21
22
|
Spin preloads your Rails environment to speed up your autotest(ish) workflow.
|
22
23
|
USAGE
|
23
|
-
|
24
|
-
exit 1
|
25
24
|
end
|
26
25
|
|
27
26
|
def socket_file
|
@@ -29,12 +28,8 @@ def socket_file
|
|
29
28
|
[Dir.tmpdir, key].join('/')
|
30
29
|
end
|
31
30
|
|
32
|
-
def require_relative?
|
33
|
-
@require_relative ||= respond_to?(:require_relative)
|
34
|
-
end
|
35
|
-
|
36
31
|
# ## spin serve
|
37
|
-
def serve
|
32
|
+
def serve(force_rspec = false)
|
38
33
|
file = socket_file
|
39
34
|
# We delete the tmp file for the Unix socket if it already exists. The file
|
40
35
|
# is scoped to the `pwd`, so if it already exists then it must be from an
|
@@ -66,30 +61,31 @@ def serve
|
|
66
61
|
end
|
67
62
|
|
68
63
|
loop do
|
69
|
-
# Since `spin push` reconnects each time it has
|
64
|
+
# Since `spin push` reconnects each time it has new files for us we just
|
70
65
|
# need to accept(2) connections from it.
|
71
66
|
conn = socket.accept
|
72
|
-
# This should be a relative
|
73
|
-
|
67
|
+
# This should be a list of relative paths to files.
|
68
|
+
files = conn.gets.chomp
|
69
|
+
files = files.split(File::PATH_SEPARATOR)
|
74
70
|
|
75
71
|
# We fork(2) before loading the file so that our pristine preloaded
|
76
72
|
# environment is untouched. The child process will load whatever code it
|
77
73
|
# needs to, then it exits and we're back to the baseline preloaded app.
|
78
74
|
fork do
|
79
75
|
puts
|
80
|
-
puts "Loading #{
|
76
|
+
puts "Loading #{files.inspect}"
|
81
77
|
|
82
78
|
# Unfortunately rspec's interface isn't as simple as just requiring the
|
83
79
|
# test file that you want to run (suddenly test/unit seems like the less
|
84
80
|
# crazy one!).
|
85
|
-
if defined?(RSpec)
|
81
|
+
if defined?(RSpec) || force_rspec
|
86
82
|
# We pretend the filepath came in as an argument and duplicate the
|
87
83
|
# behaviour of the `rspec` binary.
|
88
|
-
ARGV.push
|
84
|
+
ARGV.push files
|
89
85
|
require 'rspec/autorun'
|
90
86
|
else
|
91
87
|
# We require the full path of the file here in the child process.
|
92
|
-
require File.expand_path
|
88
|
+
files.each { |f| require File.expand_path f }
|
93
89
|
end
|
94
90
|
end
|
95
91
|
|
@@ -113,18 +109,44 @@ def push
|
|
113
109
|
# We reject anything in ARGV that isn't a file that exists. This takes
|
114
110
|
# care of scripts that specify files like `spin push -r file.rb`. The `-r`
|
115
111
|
# bit will just be ignored.
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
112
|
+
#
|
113
|
+
# We build a string like `file1.rb:file2.rb` and pass it up to the server.
|
114
|
+
f = files_to_load.select { |f| File.exist?(f) }.join(File::PATH_SEPARATOR)
|
115
|
+
puts "Spinning up #{f}"
|
116
|
+
# We put the filenames on the socket for the server to read and then load.
|
117
|
+
socket.puts f
|
121
118
|
rescue Errno::ECONNREFUSED
|
122
119
|
abort "Connection was refused. Have you started up `spin serve` yet?"
|
123
120
|
end
|
124
121
|
|
122
|
+
force_rspec = false
|
123
|
+
options = OptionParser.new do |opts|
|
124
|
+
opts.banner = usage
|
125
|
+
opts.separator ""
|
126
|
+
opts.separator "Options:"
|
127
|
+
|
128
|
+
opts.on("-I", "--load-path=DIR#{File::PATH_SEPARATOR}DIR", "Appends directory to $LOAD_PATH") do |dirs|
|
129
|
+
$LOAD_PATH.concat(dirs.split(File::PATH_SEPARATOR))
|
130
|
+
end
|
131
|
+
|
132
|
+
opts.on('--rspec', 'Force the selected test framework to RSpec') do |v|
|
133
|
+
force_rspec = v
|
134
|
+
end
|
135
|
+
|
136
|
+
opts.on('-e', 'Stub to keep kicker happy')
|
137
|
+
|
138
|
+
opts.on('-h', '--help') do
|
139
|
+
$stderr.puts opts
|
140
|
+
exit 1
|
141
|
+
end
|
142
|
+
end
|
143
|
+
options.parse!
|
144
|
+
|
125
145
|
subcommand = ARGV.shift
|
126
146
|
case subcommand
|
127
|
-
when 'serve' then serve
|
147
|
+
when 'serve' then serve(force_rspec)
|
128
148
|
when 'push' then push
|
129
|
-
else
|
149
|
+
else
|
150
|
+
$stderr.puts options
|
151
|
+
exit 1
|
130
152
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jesse Storimer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-02 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|