reel-rack 0.0.1.pre → 0.0.1.pre2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 295c91157e742548431a304bbbec23735c0311ac
4
- data.tar.gz: fe66822f852b7581f06f0ca16fec4da0a59e3267
3
+ metadata.gz: 43b21d6af7dcc1fe337503181c1db02b1872811f
4
+ data.tar.gz: 6e8577ce53c98f06345be8ec201b99cbb1c33982
5
5
  SHA512:
6
- metadata.gz: 3b3293afdaec98ab0d1adafa7fdd255359c6574d7daeb209e551b7b1ff747dfc5f143e10b77f1f92789b0092c60e01a9d0f32333e77d39ace26a66b14deb0ffc
7
- data.tar.gz: bd8f4969fcfc9824da91928c52db2daa6f0689e3f4325b7635a60b8d91e32535bf48ed92f5ca2fd52376b2fb64d0d338cf7742acd070c359da7dc582b42883e0
6
+ metadata.gz: cd2c574401da814bf72f86971a958a04bc0cc196e8d02d183b14854e74c9a69d9426cc7b1cb7686079deeea2ad81dbeb72f056c3901ffee57e0a2f1c3415a414
7
+ data.tar.gz: 263c1f3be49b9cb573a012d65f34b5c8e25dfad80bab99b1dd8143b0eef4a3e4c51355a23a0857a6c6e759683b30fcf04ae8e99c3d552b1acad8973a9152b8bb
@@ -12,16 +12,8 @@ module Rack
12
12
  def self.run(app, options = {})
13
13
  options = DEFAULT_OPTIONS.merge(options)
14
14
 
15
- unless options[:quiet]
16
- app = Rack::CommonLogger.new(app, STDOUT)
17
- end
18
-
19
- if options[:environment]
20
- ENV['RACK_ENV'] = options[:environment].to_s
21
- end
22
-
23
- Celluloid.logger.info "A Reel good HTTP server! (Codename \"#{::Reel::CODENAME}\")"
24
- Celluloid.logger.info "Listening on #{options[:host]}:#{options[:port]}"
15
+ app = Rack::CommonLogger.new(app, STDOUT) unless options[:quiet]
16
+ ENV['RACK_ENV'] = options[:environment].to_s if options[:environment]
25
17
 
26
18
  supervisor = ::Reel::Rack::Server.supervise_as(:reel_rack_server, app, options)
27
19
 
@@ -30,8 +22,6 @@ module Rack
30
22
  rescue Interrupt
31
23
  Celluloid.logger.info "Interrupt received... shutting down"
32
24
  supervisor.terminate
33
- Celluloid.join(supervisor)
34
- Celluloid.logger.info "That's all, folks!"
35
25
  end
36
26
  end
37
27
  end
data/lib/reel/rack/cli.rb CHANGED
@@ -1,16 +1,52 @@
1
1
  require 'reel/rack'
2
+ require 'optparse'
2
3
 
3
4
  module Reel
4
5
  module Rack
5
6
  class CLI
6
7
  def initialize(argv)
7
8
  @argv = argv
8
- @rackup = "config.ru"
9
+ @options = {
10
+ addr: "localhost",
11
+ port: 3000,
12
+ quiet: false,
13
+ rackup: "config.ru"
14
+ }
15
+ parser
16
+ end
17
+
18
+ def parser
19
+ @parser ||= OptionParser.new do |o|
20
+ o.banner = "reel-rack <options> <rackup file>"
21
+
22
+ o.on "-a", "--addr ADDR", "Address to listen on (default #{@options[:addr]})" do |addr|
23
+ @options[:addr] = addr
24
+ end
25
+
26
+ o.on "-p", "--port PORT", "Port to bind to (default #{@options[:port]})" do |port|
27
+ @options[:port] = port
28
+ end
29
+
30
+ o.on "-q", "--quiet", "Suppress normal logging output" do
31
+ @options[:quiet] = true
32
+ end
33
+
34
+ o.on_tail "-h", "--help", "Show help" do
35
+ STDOUT.puts @parser
36
+ exit 1
37
+ end
38
+ end
9
39
  end
10
40
 
11
41
  def run
12
- app, options = ::Rack::Builder.parse_file(@rackup)
42
+ @parser.parse! @argv
43
+ @options[:rackup] = @argv.shift if @argv.last
44
+
45
+ app, options = ::Rack::Builder.parse_file(@options[:rackup])
46
+ options.merge!(@options)
13
47
  ::Rack::Handler::Reel.run(app, options)
48
+
49
+ Celluloid.logger.info "That's all, folks!"
14
50
  end
15
51
  end
16
52
  end
@@ -7,11 +7,17 @@ require 'rack'
7
7
  module Reel
8
8
  module Rack
9
9
  class Server < Server
10
+ include Celluloid::Logger
11
+
10
12
  attr_reader :app
13
+
11
14
  def initialize(app, options)
12
15
  raise ArgumentError, "no host given" unless options[:host]
13
16
  raise ArgumentError, "no port given" unless options[:port]
14
17
 
18
+ info "A Reel good HTTP server! (Codename \"#{::Reel::CODENAME}\")"
19
+ info "Listening on http://#{options[:host]}:#{options[:port]}"
20
+
15
21
  super(options[:host], options[:port], &method(:on_connection))
16
22
  @app = app
17
23
  end
@@ -35,12 +41,15 @@ module Reel
35
41
 
36
42
  status, headers, body = app.call ::Rack::MockRequest.env_for(request.url, options)
37
43
 
38
- if body.respond_to? :each
44
+ if body.respond_to?(:to_str)
45
+ request.respond status_symbol(status), headers, body.to_str
46
+ elsif body.respond_to?(:each)
39
47
  request.respond status_symbol(status), headers.merge(:transfer_encoding => :chunked)
40
48
  body.each { |chunk| request << chunk }
41
49
  request.finish_response
42
50
  else
43
- request.respond status_symbol(status), headers, body
51
+ Logger.error("don't know how to render: #{body.inspect}")
52
+ request.respond :internal_server_error, "An error occurred processing your request"
44
53
  end
45
54
 
46
55
  body.close if body.respond_to? :close
@@ -1,5 +1,5 @@
1
1
  module Reel
2
2
  module Rack
3
- VERSION = "0.0.1.pre"
3
+ VERSION = "0.0.1.pre2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reel-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre
4
+ version: 0.0.1.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-06 00:00:00.000000000 Z
12
+ date: 2013-09-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: reel