jeanine 0.1.0 → 0.2.0

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: 8d88a21a82401395ddca515402a07e3155939eb0
4
- data.tar.gz: e6edce8a4097864466149cf6769765332a868c76
3
+ metadata.gz: a9120ffa8994858a7560330fa0afbe1bf18e2f94
4
+ data.tar.gz: fd326e260cc8c90a5b70b8b8ad4a1cd5b0b9869a
5
5
  SHA512:
6
- metadata.gz: 17f7d684adeefc7ec56e7244c6c53fddeafb9d037e4a1ee9aab94d8925193a39a95d0a079ba2aad85ae3f5a64b972315a7893f6ced6d07ba7e693923be9cc67e
7
- data.tar.gz: 82082d64a1620c947e51aa84d9ada5701825c0525061cd930022b8ef68611338570fc64f20038a4605e48bf1d27578c668ff2923a0ef7d88bc3b55435792877d
6
+ metadata.gz: 8b11b5b73abed4a7df44caf5a7b53ad6d2d52616fc23658e8c0d864239c0dc7b3fdfb6837c6d611f593944ad2518d92cc9af945ec3185a7bdfd783f913c3309c
7
+ data.tar.gz: 2ca9b7d2196c08e57bda6f983cfb0a1da71c06772bb6b42b76deb0aa941d5cb454eef4041d9834f8b3eeea9644d5a86b22e48de5f6b951a32e39481d9ac631a4
@@ -1,18 +1,22 @@
1
1
  require 'jeanine/callbacks'
2
2
  require 'jeanine/mimes'
3
3
  require 'jeanine/request'
4
+ require 'jeanine/rescuing'
4
5
  require 'jeanine/response'
5
6
  require 'jeanine/renderer'
6
7
  require 'jeanine/routing'
8
+ require 'jeanine/session'
7
9
 
8
10
  module Jeanine
9
11
  class App
12
+ include Session
10
13
  include Routing::Evaluation
11
14
  attr_reader :request, :response
15
+
12
16
  class << self
13
- include Routing::DSL
14
17
  include Callbacks
15
-
18
+ include Routing::DSL
19
+ include Rescuing
16
20
  alias :_new :new
17
21
  def new(*args, &block)
18
22
  initialize!
@@ -37,11 +41,24 @@ module Jeanine
37
41
  end
38
42
  end
39
43
 
44
+ include Rescuing
45
+
40
46
  def call(env)
41
- @env = env
42
- @request = Jeanine::Request.new(env)
43
- @response = Jeanine::Response.new
44
- catch(:halt) { route_eval }
47
+ begin
48
+ @env = env
49
+ @request = Jeanine::Request.new(env)
50
+ @response = Jeanine::Response.new
51
+ catch(:halt) { route_eval }
52
+ rescue => error
53
+ handler = self.class.rescue_handlers[error.class]
54
+ raise error unless handler
55
+ if handler.is_a?(Symbol)
56
+ @response.write(send(handler, error))
57
+ else
58
+ @response.write(instance_exec(error, &handler))
59
+ end
60
+ @response.complete!
61
+ end
45
62
  end
46
63
 
47
64
  private
@@ -0,0 +1,17 @@
1
+ module Jeanine
2
+ module Rescuing
3
+ def rescue_from(*exceptions, with: nil, &block)
4
+ exceptions.each do |exception|
5
+ if with
6
+ rescue_handlers[exception] = with
7
+ else
8
+ rescue_handlers[exception] = block
9
+ end
10
+ end
11
+ end
12
+
13
+ def rescue_handlers
14
+ @rescue_handlers ||= {}
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module Jeanine
2
+ module Session
3
+ def session
4
+ env['rack.session']
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Jeanine
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeanine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Brody
@@ -87,11 +87,13 @@ files:
87
87
  - lib/jeanine/path_proxy.rb
88
88
  - lib/jeanine/renderer.rb
89
89
  - lib/jeanine/request.rb
90
+ - lib/jeanine/rescuing.rb
90
91
  - lib/jeanine/response.rb
91
92
  - lib/jeanine/router.rb
92
93
  - lib/jeanine/routing.rb
93
94
  - lib/jeanine/routing/dsl.rb
94
95
  - lib/jeanine/routing/evaluation.rb
96
+ - lib/jeanine/session.rb
95
97
  - lib/jeanine/version.rb
96
98
  - lib/jeanine/view.rb
97
99
  homepage: https://github.com/joshmn/jeanine