startbrick 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -10
- data/bin/startbrick +26 -1
- data/lib/startbrick/version.rb +1 -1
- data/lib/startbrick.rb +1 -36
- data/startbrick.gemspec +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Startbrick
|
2
2
|
|
3
|
-
How much of your Rails dev time is
|
3
|
+
How much of your Rails dev time is wasted waiting for this:
|
4
4
|
|
5
5
|
$ rails s
|
6
6
|
=> Booting WEBrick
|
@@ -21,7 +21,7 @@ to turn into this:
|
|
21
21
|
|
22
22
|
just so you can manually load the Rails app in your web browser?
|
23
23
|
|
24
|
-
**Startbrick** is a thin wrapper
|
24
|
+
**Startbrick** is a thin wrapper around the `rails s` command that
|
25
25
|
automatically opens your Rails app in your default web browser when it's ready
|
26
26
|
to accept requests.
|
27
27
|
|
@@ -32,21 +32,20 @@ Install the gem with
|
|
32
32
|
Startbrick works with Rails 3. It doesn't work with JRuby because it
|
33
33
|
uses `Kernel#fork`.
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
gem 'startbrick'
|
38
|
-
|
39
|
-
and start your Rails app with this command:
|
35
|
+
Start your Rails app with this command:
|
40
36
|
|
41
37
|
startbrick
|
42
38
|
|
43
|
-
|
39
|
+
The browser should open to your app once the server is ready to accept
|
40
|
+
requests.
|
41
|
+
|
42
|
+
You can add any of the arguments that you can pass to the `rails s`
|
44
43
|
command.
|
45
44
|
|
46
45
|
## Optional .startbrick script
|
47
46
|
|
48
|
-
By default, Startbrick runs this shell command when
|
49
|
-
requests:
|
47
|
+
By default, Startbrick runs this shell command when the Rails server is
|
48
|
+
ready for requests:
|
50
49
|
|
51
50
|
open "http://#{BindAddress}:#{Port}"
|
52
51
|
|
data/bin/startbrick
CHANGED
@@ -1,4 +1,29 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
args = ARGV.dup
|
6
|
+
|
7
|
+
options = {:Host => 'localhost', :Port => '3000'}
|
8
|
+
|
9
|
+
opt_parser = OptionParser.new do |opts|
|
10
|
+
opts.on("-p", "--port=port", Integer,
|
11
|
+
"Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
|
12
|
+
opts.on("-b", "--binding=ip", String,
|
13
|
+
"Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| options[:Host] = v }
|
14
|
+
end
|
15
|
+
|
16
|
+
opt_parser.parse! args
|
17
|
+
puts options.inspect
|
18
|
+
|
19
|
+
cmd = "rails s #{ARGV.join(' ').strip}"
|
20
|
+
|
21
|
+
open_cmd = "open 'http://#{options[:Host]}:#{options[:Port]}'"
|
22
|
+
puts open_cmd
|
23
|
+
fork do
|
24
|
+
`while ! nc -z localhost #{options[:Port]}; do sleep 0.1; done; echo 'opening browser'; #{open_cmd}`
|
25
|
+
end
|
26
|
+
|
3
27
|
puts cmd
|
28
|
+
|
4
29
|
exec cmd
|
data/lib/startbrick/version.rb
CHANGED
data/lib/startbrick.rb
CHANGED
@@ -1,38 +1,3 @@
|
|
1
|
-
|
2
|
-
require 'rack/handler/webrick'
|
3
|
-
|
4
|
-
module Rack
|
5
|
-
module Handler
|
6
|
-
SCRIPT_FILE = '.startbrick'
|
7
|
-
|
8
|
-
class Startbrick < Rack::Handler::WEBrick
|
9
|
-
def self.run(app, options={})
|
1
|
+
module Startbrick
|
10
2
|
|
11
|
-
options[:BindAddress] = options.delete(:Host) if options[:Host]
|
12
|
-
|
13
|
-
options[:StartCallback] = if ::File.size?(SCRIPT_FILE)
|
14
|
-
script = ::File.read(SCRIPT_FILE)
|
15
|
-
puts "Loading #{SCRIPT_FILE} script:\n\n#{script.gsub(/^/, ' ')}"
|
16
|
-
Proc.new {
|
17
|
-
puts "Executing #{SCRIPT_FILE}"
|
18
|
-
fork { `bash #{SCRIPT_FILE}` }
|
19
|
-
}
|
20
|
-
else
|
21
|
-
Proc.new {
|
22
|
-
url = "http://#{options[:BindAddress]}:#{options[:Port]}"
|
23
|
-
cmd = "open #{url}"
|
24
|
-
puts "Running '#{cmd}'"
|
25
|
-
fork { `#{cmd}` }
|
26
|
-
}
|
27
|
-
|
28
|
-
end
|
29
|
-
@server = ::WEBrick::HTTPServer.new(options)
|
30
|
-
@server.mount "/", Rack::Handler::WEBrick, app
|
31
|
-
yield @server if block_given?
|
32
|
-
@server.start
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
3
|
end
|
38
|
-
|
data/startbrick.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: startbrick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,9 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-05 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: rails s wrapper
|
15
15
|
email:
|
16
16
|
- dhchoi@gmail.com
|
17
17
|
executables:
|
@@ -48,5 +48,5 @@ rubyforge_project:
|
|
48
48
|
rubygems_version: 1.8.11
|
49
49
|
signing_key:
|
50
50
|
specification_version: 3
|
51
|
-
summary:
|
51
|
+
summary: rails s wrapper
|
52
52
|
test_files: []
|