startbrick 0.0.5 → 0.0.6

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Startbrick
2
2
 
3
- How much of your Rails dev time is utterly wasted waiting for this:
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 gem around Rack::Handler::WEBrick that
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
- To use startbrick, puts this line in your Gemfile
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
- You can add any of the flagged arguments that you can pass to the `rails s`
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 WEBrick is ready for
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
- cmd = "rails s #{ARGV.join(' ').strip} Startbrick"
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
@@ -1,3 +1,3 @@
1
1
  module Startbrick
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
data/lib/startbrick.rb CHANGED
@@ -1,38 +1,3 @@
1
- require 'rack'
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
@@ -3,7 +3,7 @@ require 'startbrick/version'
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "startbrick"
6
- s.description = "WEBrick wrapper"
6
+ s.description = "rails s wrapper"
7
7
  s.version = Startbrick::VERSION
8
8
  s.summary = s.description
9
9
  s.authors = ["Daniel Choi"]
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.5
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-03 00:00:00.000000000Z
12
+ date: 2011-11-05 00:00:00.000000000Z
13
13
  dependencies: []
14
- description: WEBrick wrapper
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: WEBrick wrapper
51
+ summary: rails s wrapper
52
52
  test_files: []