lookout-rack-utils 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzIxNjcxNGNjYjY5YWRjNTZjMTZiYWM5YTZlZGQ5MTI4NDQ5OGJiNw==
5
+ data.tar.gz: !binary |-
6
+ ZWJjMzVjYWFmZTk3YzYxOTcwMTc4MzZhMzRjNGU3MTI5MGI0YjEyNg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MjIzYjIyNjdkMTkzZWZmYWM0MDlmMjNiMGUyNjkyOTFlYjQxMWI2ZjA3ZjMz
10
+ ZTUwODFkNmIxMzNhMjRhN2VmZmVmNWM5NjA1ZGMyZDQwODBmNGY4YmU1MjRh
11
+ MDk3ZWJjYTAwNmE3Y2JmZTI5YWU0MmM0MWIzNDYzNzAzZGE2ZWU=
12
+ data.tar.gz: !binary |-
13
+ YjAzMGU4YjdkNmE2M2U2YmZlZTk4ZDEyMTAzM2I3Y2Q0ZmRjZTJmYTE1NmNm
14
+ MjQ5YjcxYTkzMjRkNzEyZjllODJkZmU2MTJhODY4ODNkYjk5YTE4YjE5Zjll
15
+ MWM3OTM0NWUzZTMwODc1NDVmMDI5MjY2OTFkYzMxMzk0ODlmOWU=
data/README.md CHANGED
@@ -29,6 +29,10 @@ Or install it yourself as:
29
29
  s.port = 8125
30
30
  end
31
31
  ```
32
+
33
+ You will also need to prime the instance before using it by calling
34
+ `Lookout::Rack::Utils::Graphite.instance`.
35
+
32
36
  ### Lookout::Rack::Utils::I18n
33
37
  You'll need configatron set up:
34
38
 
@@ -1,11 +1,25 @@
1
1
  module Lookout::Rack::Utils
2
2
  module Subroute
3
+ HTTP_METHODS = %w(DELETE GET HEAD OPTIONS LINK PATCH POST PUT TRACE UNLINK).freeze
4
+
3
5
  def subroute!(relative_path, options={})
4
- http_verb = request.request_method
6
+ # Create a copy of our App instance to preserve the state of the
7
+ # caller's env hash
8
+ subserver = dup
9
+ request_opts = {'PATH_INFO' => relative_path}
10
+
11
+ request_opts['REQUEST_METHOD'] = options.delete(:request_method).upcase if options[:request_method]
12
+ http_verb = request_opts['REQUEST_METHOD'] || subserver.request.request_method
13
+
14
+ raise ArgumentError, "Invalid http method: #{http_verb}" unless HTTP_METHODS.include?(http_verb)
15
+
5
16
  # modify rack environment using Rack::Request- store passed in key/value
6
17
  # pairs into hash associated with the parameters of the current http verb
7
- options.each { |k,v| request.send(http_verb)[k] = v }
8
- subcode, subheaders, body = call(env.merge('PATH_INFO' => relative_path))
18
+ options.each { |k,v| subserver.request.send(http_verb)[k] = v }
19
+ # Invoking Sinatra::Base#call! on our duplicated app instance. Sinatra's
20
+ # call will dup the app instance and then call!, so skip Sinatra's dup
21
+ # since we've done that here.
22
+ subcode, subheaders, body = subserver.call!(env.merge(request_opts))
9
23
  return [subcode, body.first]
10
24
  end
11
25
 
@@ -1,7 +1,7 @@
1
1
  module Lookout
2
2
  module Rack
3
3
  module Utils
4
- VERSION = "1.5.0"
4
+ VERSION = "1.6.0"
5
5
  end
6
6
  end
7
7
  end
@@ -17,6 +17,20 @@ describe Lookout::Rack::Utils::Subroute, :type => :route do
17
17
  get '/subrouted/:id' do |id|
18
18
  subroute!('/test_route', :id => id)
19
19
  end
20
+
21
+ delete '/test_delete' do
22
+ status 201
23
+ { :deleted => true }.to_json
24
+ end
25
+
26
+ get '/test_delete' do
27
+ subroute!('/test_delete', :request_method => 'DELETE')
28
+ end
29
+
30
+ get '/multiroute' do
31
+ subroute!('/test_delete', :request_method => 'DELETE')
32
+ subroute!('/test_route', :id => 1)
33
+ end
20
34
  end
21
35
  end
22
36
 
@@ -36,6 +50,33 @@ describe Lookout::Rack::Utils::Subroute, :type => :route do
36
50
  expect([subrouted.status, subrouted.body]).to eql [200, body]
37
51
  end
38
52
  end
53
+
54
+ context 'changing the http verb' do
55
+ context 'to a valid verb' do
56
+ subject(:subrouted) { get "/test_delete" }
57
+
58
+ its(:status) { should be 201 }
59
+
60
+ it 'should return expected output' do
61
+ expect(JSON.parse(subrouted.body)['deleted']).to be_true
62
+ end
63
+ end
64
+
65
+ context 'to an invalid verb' do
66
+ subject(:subrouted) { subroute!('/test_delete_invalid', :request_path => 'DELATE') }
67
+
68
+ it 'should throw an error' do
69
+ expect { subrouted }.to raise_error
70
+ end
71
+ end
72
+
73
+ context 'with multiple subroutes' do
74
+ subject(:subrouted) { get '/multiroute' }
75
+ it 'should return the status and body of the second subroute' do
76
+ expect([subrouted.status, subrouted.body]).to eql [200, { :id => 1 }.to_json]
77
+ end
78
+ end
79
+ end
39
80
  end
40
81
 
41
82
  describe '#succeeded?' do
metadata CHANGED
@@ -1,170 +1,204 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: lookout-rack-utils
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.5.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.6.0
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Ian Smith
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2014-03-04 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
11
+ date: 2014-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
16
14
  name: bundler
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
20
17
  - - ~>
21
- - !ruby/object:Gem::Version
22
- version: "1.3"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
23
20
  type: :development
24
21
  prerelease: false
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
27
28
  name: rake
28
- requirement: &id002 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: "0"
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
38
42
  name: rspec
39
- requirement: &id003 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- version: "0"
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
45
48
  type: :development
46
49
  prerelease: false
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
49
56
  name: rack-test
50
- requirement: &id004 !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: "0"
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
56
62
  type: :development
57
63
  prerelease: false
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
60
70
  name: sinatra
61
- requirement: &id005 !ruby/object:Gem::Requirement
62
- none: false
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: "0"
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
67
76
  type: :development
68
77
  prerelease: false
69
- version_requirements: *id005
70
- - !ruby/object:Gem::Dependency
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
71
84
  name: timecop
72
- requirement: &id006 !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: "0"
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
78
90
  type: :development
79
91
  prerelease: false
80
- version_requirements: *id006
81
- - !ruby/object:Gem::Dependency
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
82
98
  name: i18n
83
- requirement: &id007 !ruby/object:Gem::Requirement
84
- none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- version: "0"
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
89
104
  type: :runtime
90
105
  prerelease: false
91
- version_requirements: *id007
92
- - !ruby/object:Gem::Dependency
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
93
112
  name: rack
94
- requirement: &id008 !ruby/object:Gem::Requirement
95
- none: false
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- version: "0"
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
100
118
  type: :runtime
101
119
  prerelease: false
102
- version_requirements: *id008
103
- - !ruby/object:Gem::Dependency
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
104
126
  name: rack-graphite
105
- requirement: &id009 !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: "0"
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
111
132
  type: :runtime
112
133
  prerelease: false
113
- version_requirements: *id009
114
- - !ruby/object:Gem::Dependency
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
115
140
  name: rack-requestash
116
- requirement: &id010 !ruby/object:Gem::Requirement
117
- none: false
118
- requirements:
119
- - - ">="
120
- - !ruby/object:Gem::Version
121
- version: "0"
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
122
146
  type: :runtime
123
147
  prerelease: false
124
- version_requirements: *id010
125
- - !ruby/object:Gem::Dependency
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
126
154
  name: configatron
127
- requirement: &id011 !ruby/object:Gem::Requirement
128
- none: false
129
- requirements:
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
130
157
  - - ~>
131
- - !ruby/object:Gem::Version
132
- version: "2.13"
158
+ - !ruby/object:Gem::Version
159
+ version: '2.13'
133
160
  type: :runtime
134
161
  prerelease: false
135
- version_requirements: *id011
136
- - !ruby/object:Gem::Dependency
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ~>
165
+ - !ruby/object:Gem::Version
166
+ version: '2.13'
167
+ - !ruby/object:Gem::Dependency
137
168
  name: log4r
138
- requirement: &id012 !ruby/object:Gem::Requirement
139
- none: false
140
- requirements:
141
- - - ">="
142
- - !ruby/object:Gem::Version
143
- version: "0"
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
144
174
  type: :runtime
145
175
  prerelease: false
146
- version_requirements: *id012
147
- - !ruby/object:Gem::Dependency
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
148
182
  name: lookout-statsd
149
- requirement: &id013 !ruby/object:Gem::Requirement
150
- none: false
151
- requirements:
152
- - - ">="
153
- - !ruby/object:Gem::Version
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
154
187
  version: 0.7.0
155
188
  type: :runtime
156
189
  prerelease: false
157
- version_requirements: *id013
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ! '>='
193
+ - !ruby/object:Gem::Version
194
+ version: 0.7.0
158
195
  description: A collection of rack utils.
159
- email:
196
+ email:
160
197
  - ian.smith@lookout.com
161
198
  executables: []
162
-
163
199
  extensions: []
164
-
165
200
  extra_rdoc_files: []
166
-
167
- files:
201
+ files:
168
202
  - .gitignore
169
203
  - Gemfile
170
204
  - LICENSE.txt
@@ -185,40 +219,31 @@ files:
185
219
  - spec/subroute_spec.rb
186
220
  - spec/support/routehelpers.rb
187
221
  - spec/support/subroutehelpers.rb
188
- homepage: ""
189
- licenses:
222
+ homepage: ''
223
+ licenses:
190
224
  - MIT
225
+ metadata: {}
191
226
  post_install_message:
192
227
  rdoc_options: []
193
-
194
- require_paths:
228
+ require_paths:
195
229
  - lib
196
- required_ruby_version: !ruby/object:Gem::Requirement
197
- none: false
198
- requirements:
199
- - - ">="
200
- - !ruby/object:Gem::Version
201
- hash: 3856689036968627434
202
- segments:
203
- - 0
204
- version: "0"
205
- required_rubygems_version: !ruby/object:Gem::Requirement
206
- none: false
207
- requirements:
208
- - - ">="
209
- - !ruby/object:Gem::Version
210
- hash: 3856689036968627434
211
- segments:
212
- - 0
213
- version: "0"
230
+ required_ruby_version: !ruby/object:Gem::Requirement
231
+ requirements:
232
+ - - ! '>='
233
+ - !ruby/object:Gem::Version
234
+ version: '0'
235
+ required_rubygems_version: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - ! '>='
238
+ - !ruby/object:Gem::Version
239
+ version: '0'
214
240
  requirements: []
215
-
216
241
  rubyforge_project:
217
- rubygems_version: 1.8.23
242
+ rubygems_version: 2.2.2
218
243
  signing_key:
219
- specification_version: 3
220
- summary: ""
221
- test_files:
244
+ specification_version: 4
245
+ summary: ''
246
+ test_files:
222
247
  - spec/graphite_spec.rb
223
248
  - spec/i18n_spec.rb
224
249
  - spec/log_spec.rb