newark 0.0.6 → 0.0.7

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: fed1a9e5d5021c32f65e7813c10a5dbc1f409e83
4
- data.tar.gz: aa12c7aba2fec27ac9bb7dcdb9e92202dcf1d03c
3
+ metadata.gz: 5b1b007d826796f975e53a238c1f3f8bec78b94d
4
+ data.tar.gz: 361aa3310e4bd3231f5cba710be13adbacf2a67a
5
5
  SHA512:
6
- metadata.gz: ee6980bb5d7b94957b37ce3cb21bbdd19f0b65cd27d232aefbbaf2a563db3cdcbf81bae63edf36ecf73c4248209f70e01eda7f71900f0646092fc6298aebfc74
7
- data.tar.gz: 6ff2442b777d6a93d3f2c4fc892729e1be9530ffef45e556f79bb7681420dc13cc15dffd9cb19b877ee8d5d99cd8368989f82eaf32f2efc761e3751a3e6f28de
6
+ metadata.gz: d1c10396d7c1182363d55352e3998b8549a396ca1b5ecbaa5fab7925001c67936b863e76acf052bc03d1ac890619cff74333e24d0e995602a724c9a93983af94
7
+ data.tar.gz: 90ad0f2f607cd75ff633392ce51e03c3ae0f858c07021067f2e42efa548f57cf84a4de904587cf448c9e4e23f272ec9bf9f36413122c638a55aa59751921f980
@@ -1,6 +1,7 @@
1
1
  lib = File.expand_path('../../lib', __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
+ require 'benchmark'
4
5
  require 'benchmark/ips'
5
6
  require 'rack/test'
6
7
  require 'newark'
data/lib/newark/app.rb CHANGED
@@ -46,6 +46,13 @@ module Newark
46
46
 
47
47
  attr_reader :request, :response
48
48
 
49
+ def initialize(*)
50
+ super
51
+ @before_hooks = self.class.instance_variable_get(:@before_hooks)
52
+ @after_hooks = self.class.instance_variable_get(:@after_hooks)
53
+ @routes = self.class.instance_variable_get(:@routes)
54
+ end
55
+
49
56
  def call(env)
50
57
  dup._call(env)
51
58
  end
@@ -69,10 +76,12 @@ module Newark
69
76
  route = match_route
70
77
  if route
71
78
  request.params.merge!(route.params)
72
- exec_before_hooks
73
- response.body = exec_handler(route.handler)
74
- exec_after_hooks
75
- response.finish
79
+ if exec_before_hooks
80
+ response.body = exec(route.handler)
81
+ exec_after_hooks
82
+ end
83
+ status, headers, body = response.finish
84
+ [status, headers, body.respond_to?(:body) ? body.body : body]
76
85
  else
77
86
  FOUR_O_FOUR
78
87
  end
@@ -85,7 +94,7 @@ module Newark
85
94
  end
86
95
 
87
96
  def routes
88
- self.class.instance_variable_get(:@routes)[@request.request_method]
97
+ @routes[@request.request_method]
89
98
  end
90
99
 
91
100
  def exec(action)
@@ -101,17 +110,17 @@ module Newark
101
110
  end
102
111
 
103
112
  def exec_before_hooks
104
- exec_hooks self.class.instance_variable_get(:@before_hooks)
113
+ exec_hooks @before_hooks
105
114
  end
106
115
 
107
116
  def exec_after_hooks
108
- exec_hooks self.class.instance_variable_get(:@after_hooks)
117
+ exec_hooks @after_hooks
109
118
  end
110
119
 
111
120
  def exec_hooks(hooks)
112
- return if hooks.nil?
121
+ return true if hooks.nil?
113
122
  hooks.each do |hook|
114
- exec(hook)
123
+ return false if exec(hook) == false
115
124
  end
116
125
  end
117
126
  end
@@ -12,6 +12,10 @@ module Newark
12
12
  URI(URI.escape(uri))
13
13
  end
14
14
 
15
+ def path_info
16
+ @path_info ||= super == '/' ? super : super.sub(/\/$/, '')
17
+ end
18
+
15
19
  def params
16
20
  @params ||= ActiveSupport::HashWithIndifferentAccess.new(super)
17
21
  end
data/lib/newark/route.rb CHANGED
@@ -41,7 +41,7 @@ module Newark
41
41
  def path_params(path)
42
42
  match_path(path)
43
43
  match_params(path)
44
- path
44
+ path != '/' ? path.sub(/\/$/, '') : path
45
45
  end
46
46
 
47
47
  def match_path(path)
@@ -1,3 +1,3 @@
1
1
  module Newark
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
data/newark.gemspec CHANGED
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'pry'
28
28
  spec.add_development_dependency 'benchmark-ips'
29
29
  spec.add_development_dependency 'multi_json'
30
+ spec.add_development_dependency 'minitest', '~> 4.2'
30
31
  end
data/test/helper.rb CHANGED
@@ -6,6 +6,6 @@ require 'newark'
6
6
  require 'rack/test'
7
7
  require 'minitest/autorun'
8
8
 
9
- class Minitest::Unit::TestCase
9
+ class MiniTest::Unit::TestCase
10
10
 
11
11
  end
data/test/test_app.rb CHANGED
@@ -3,6 +3,13 @@ require 'helper'
3
3
  class NameApp
4
4
  include Newark
5
5
 
6
+ before do
7
+ if params[:key] && params[:key] != '23'
8
+ response.status = 403
9
+ false
10
+ end
11
+ end
12
+
6
13
  def upcase(str)
7
14
  str.upcase
8
15
  end
@@ -15,6 +22,10 @@ class NameApp
15
22
  hello
16
23
  end
17
24
 
25
+ get '/fail' do
26
+ 'This should not be reached'
27
+ end
28
+
18
29
  get '/hello2', :hello
19
30
 
20
31
  private
@@ -24,7 +35,7 @@ class NameApp
24
35
  end
25
36
  end
26
37
 
27
- class TestApp < Minitest::Unit::TestCase
38
+ class TestApp < MiniTest::Unit::TestCase
28
39
 
29
40
  include Rack::Test::Methods
30
41
 
@@ -48,11 +59,11 @@ class TestApp < Minitest::Unit::TestCase
48
59
  assert_equal 'Hello', last_response.body
49
60
  end
50
61
 
51
- # def test_before_hooks_halting_execution
52
- # get '/'
53
- # refute last_response.ok?
54
- # assert_equal 403, last_response.status
55
- # assert_equal '', last_response.body
56
- # end
62
+ def test_before_hooks_halting_execution
63
+ get '/fail', { key: '1234' }
64
+ refute last_response.ok?
65
+ assert_equal 403, last_response.status
66
+ assert_equal '', last_response.body
67
+ end
57
68
 
58
69
  end
data/test/test_request.rb CHANGED
@@ -20,7 +20,7 @@ class RequestApp
20
20
  end
21
21
  end
22
22
 
23
- class TestRequest < Minitest::Unit::TestCase
23
+ class TestRequest < MiniTest::Unit::TestCase
24
24
 
25
25
  include Rack::Test::Methods
26
26
 
@@ -1,4 +1,5 @@
1
1
  require 'helper'
2
+ require 'multi_json'
2
3
 
3
4
  class ResponseApp
4
5
  include Newark
@@ -8,7 +9,7 @@ class ResponseApp
8
9
  end
9
10
  end
10
11
 
11
- class TestResponse < Minitest::Unit::TestCase
12
+ class TestResponse < MiniTest::Unit::TestCase
12
13
 
13
14
  include Rack::Test::Methods
14
15
 
data/test/test_router.rb CHANGED
@@ -8,6 +8,12 @@ class TestingApp
8
8
  headers['X-Newark-Version'] = Newark::VERSION
9
9
  end
10
10
 
11
+ before do
12
+ if params[:token] && params[:token] == '123456'
13
+ redirect_to 'http://example.com' && return
14
+ end
15
+ end
16
+
11
17
  after do
12
18
  headers['X-Newark-Done'] = 'true'
13
19
  end
@@ -46,9 +52,17 @@ class TestingApp
46
52
  params[:rest_of_path]
47
53
  end
48
54
 
55
+ get '/trailing_slash/' do
56
+ 'trailing_slash'
57
+ end
58
+
59
+ get '/no_trailing_slash' do
60
+ 'no_trailing_slash'
61
+ end
62
+
49
63
  end
50
64
 
51
- class TestRouter < Minitest::Unit::TestCase
65
+ class TestRouter < MiniTest::Unit::TestCase
52
66
 
53
67
  include Rack::Test::Methods
54
68
 
@@ -97,6 +111,12 @@ class TestRouter < Minitest::Unit::TestCase
97
111
  assert_equal Newark::VERSION, last_response.header['X-Newark-Version']
98
112
  end
99
113
 
114
+ def test_before_hook_stops_rendering
115
+ skip
116
+ get '/', token: '123456'
117
+ assert last_response.redirected?
118
+ end
119
+
100
120
  def test_after_hook
101
121
  get '/'
102
122
  assert_equal 'true', last_response.header['X-Newark-Done']
@@ -113,4 +133,24 @@ class TestRouter < Minitest::Unit::TestCase
113
133
  assert last_response.ok?
114
134
  assert_equal 'rest/of/path', last_response.body
115
135
  end
136
+
137
+ def test_deals_with_trailing_slashes
138
+ get '/trailing_slash/'
139
+ assert last_response.ok?
140
+ assert_equal 'trailing_slash', last_response.body
141
+
142
+ get '/trailing_slash'
143
+ assert last_response.ok?
144
+ assert_equal 'trailing_slash', last_response.body
145
+ end
146
+
147
+ def test_deals_with_no_trailing_slashes
148
+ get '/no_trailing_slash/'
149
+ assert last_response.ok?
150
+ assert_equal 'no_trailing_slash', last_response.body
151
+
152
+ get '/no_trailing_slash'
153
+ assert last_response.ok?
154
+ assert_equal 'no_trailing_slash', last_response.body
155
+ end
116
156
  end
metadata CHANGED
@@ -1,127 +1,141 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Evans
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-26 00:00:00.000000000 Z
11
+ date: 2014-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: rack
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
- - - '>='
17
+ - - ">="
17
18
  - !ruby/object:Gem::Version
18
19
  version: 1.5.2
19
- name: rack
20
- prerelease: false
21
20
  type: :runtime
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.5.2
27
27
  - !ruby/object:Gem::Dependency
28
+ name: activesupport
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - '>='
31
+ - - ">="
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
- name: activesupport
34
- prerelease: false
35
34
  type: :runtime
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
+ name: bundler
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
- - - ~>
45
+ - - "~>"
45
46
  - !ruby/object:Gem::Version
46
47
  version: '1.5'
47
- name: bundler
48
- prerelease: false
49
48
  type: :development
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.5'
55
55
  - !ruby/object:Gem::Dependency
56
+ name: rake
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
- - - '>='
59
+ - - ">="
59
60
  - !ruby/object:Gem::Version
60
61
  version: '0'
61
- name: rake
62
- prerelease: false
63
62
  type: :development
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
+ name: rack-test
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
- - - '>='
73
+ - - ">="
73
74
  - !ruby/object:Gem::Version
74
75
  version: '0'
75
- name: rack-test
76
- prerelease: false
77
76
  type: :development
77
+ prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
+ name: pry
84
85
  requirement: !ruby/object:Gem::Requirement
85
86
  requirements:
86
- - - '>='
87
+ - - ">="
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
- name: pry
90
- prerelease: false
91
90
  type: :development
91
+ prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
+ name: benchmark-ips
98
99
  requirement: !ruby/object:Gem::Requirement
99
100
  requirements:
100
- - - '>='
101
+ - - ">="
101
102
  - !ruby/object:Gem::Version
102
103
  version: '0'
103
- name: benchmark-ips
104
- prerelease: false
105
104
  type: :development
105
+ prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
+ name: multi_json
112
113
  requirement: !ruby/object:Gem::Requirement
113
114
  requirements:
114
- - - '>='
115
+ - - ">="
115
116
  - !ruby/object:Gem::Version
116
117
  version: '0'
117
- name: multi_json
118
- prerelease: false
119
118
  type: :development
119
+ prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: minitest
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '4.2'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '4.2'
125
139
  description: Because everyone should write their own framework.
126
140
  email:
127
141
  - mike@urlgonomics.com
@@ -129,8 +143,8 @@ executables: []
129
143
  extensions: []
130
144
  extra_rdoc_files: []
131
145
  files:
132
- - .gitignore
133
- - .travis.yml
146
+ - ".gitignore"
147
+ - ".travis.yml"
134
148
  - Gemfile
135
149
  - LICENSE.txt
136
150
  - README.md
@@ -153,24 +167,24 @@ homepage: ''
153
167
  licenses:
154
168
  - MIT
155
169
  metadata: {}
156
- post_install_message:
170
+ post_install_message:
157
171
  rdoc_options: []
158
172
  require_paths:
159
173
  - lib
160
174
  required_ruby_version: !ruby/object:Gem::Requirement
161
175
  requirements:
162
- - - '>='
176
+ - - ">="
163
177
  - !ruby/object:Gem::Version
164
178
  version: '0'
165
179
  required_rubygems_version: !ruby/object:Gem::Requirement
166
180
  requirements:
167
- - - '>='
181
+ - - ">="
168
182
  - !ruby/object:Gem::Version
169
183
  version: '0'
170
184
  requirements: []
171
- rubyforge_project:
185
+ rubyforge_project:
172
186
  rubygems_version: 2.2.2
173
- signing_key:
187
+ signing_key:
174
188
  specification_version: 4
175
189
  summary: Pico Web Framework
176
190
  test_files: