rocket_pants 1.5.4 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rocket_pants.rb +9 -2
- data/lib/rocket_pants/controller/versioning.rb +25 -10
- data/lib/rocket_pants/routing.rb +21 -4
- metadata +47 -50
data/lib/rocket_pants.rb
CHANGED
@@ -4,7 +4,6 @@ require 'action_dispatch/routing'
|
|
4
4
|
require 'action_controller'
|
5
5
|
|
6
6
|
require 'moneta'
|
7
|
-
require 'moneta/memory'
|
8
7
|
|
9
8
|
module RocketPants
|
10
9
|
require 'rocket_pants/error'
|
@@ -46,12 +45,20 @@ module RocketPants
|
|
46
45
|
|
47
46
|
mattr_writer :cache
|
48
47
|
|
48
|
+
begin
|
49
|
+
require 'moneta/memory'
|
50
|
+
MONETA_LEGACY = true
|
51
|
+
rescue LoadError => e
|
52
|
+
require 'moneta'
|
53
|
+
MONETA_LEGACY = false
|
54
|
+
end
|
55
|
+
|
49
56
|
class << self
|
50
57
|
alias caching_enabled? caching_enabled
|
51
58
|
alias header_metadata? header_metadata
|
52
59
|
|
53
60
|
def cache
|
54
|
-
@@cache ||= Moneta::Memory.new
|
61
|
+
@@cache ||= (MONETA_LEGACY ? Moneta::Memory : Moneta::Adapters::Memory).new
|
55
62
|
end
|
56
63
|
|
57
64
|
def env
|
@@ -1,28 +1,28 @@
|
|
1
1
|
module RocketPants
|
2
2
|
module Versioning
|
3
|
-
|
3
|
+
|
4
4
|
extend ActiveSupport::Concern
|
5
|
-
|
5
|
+
|
6
6
|
included do
|
7
7
|
class_attribute :_version_range
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
module ClassMethods
|
11
|
-
|
11
|
+
|
12
12
|
def version(version)
|
13
13
|
version = version..version if version.is_a?(Integer)
|
14
14
|
self._version_range = version
|
15
15
|
before_filter :verify_api_version
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
protected
|
21
|
-
|
21
|
+
|
22
22
|
def version
|
23
23
|
if !instance_variable_defined?(:@version)
|
24
24
|
@version = begin
|
25
|
-
version = params[:version]
|
25
|
+
version = extract_version_string_with_prefix params[:version], request.symbolized_path_parameters[:rp_prefix]
|
26
26
|
version.presence && Integer(version)
|
27
27
|
rescue ArgumentError
|
28
28
|
nil
|
@@ -30,10 +30,25 @@ module RocketPants
|
|
30
30
|
end
|
31
31
|
@version
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def verify_api_version
|
35
35
|
error! :invalid_version unless version.present? && _version_range.include?(version)
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
|
+
def extract_version_string_with_prefix(version, prefix)
|
39
|
+
if version && prefix.is_a?(Hash)
|
40
|
+
# We need to strip the text from the prefix.
|
41
|
+
prefix_regexp = /^#{prefix[:text]}/
|
42
|
+
version = version.to_s
|
43
|
+
if prefix[:required] && version !~ prefix_regexp
|
44
|
+
raise ArgumentError, "You required the route version prefix #{prefix[:text]}, but not was given."
|
45
|
+
end
|
46
|
+
version.gsub prefix_regexp, ''
|
47
|
+
else
|
48
|
+
# Otherwise, return it intact.
|
49
|
+
version
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
38
53
|
end
|
39
54
|
end
|
data/lib/rocket_pants/routing.rb
CHANGED
@@ -7,20 +7,37 @@ module RocketPants
|
|
7
7
|
# @option options [Array<Integer>, Integer] :version the single version to support
|
8
8
|
# @raise [ArgumentError] raised when the version isn't provided.
|
9
9
|
def rocket_pants(options = {}, &blk)
|
10
|
-
versions =
|
11
|
-
|
12
|
-
|
10
|
+
versions = extract_rocket_pants_versions options
|
11
|
+
|
12
|
+
defaults = {:format => 'json'}
|
13
|
+
|
14
|
+
if (optional_prefix = options.delete(:allow_prefix))
|
15
|
+
versions.map! { |v| "#{optional_prefix}?#{v}" }
|
16
|
+
defaults[:rp_prefix] = {:text => optional_prefix.to_s, :required => false}
|
17
|
+
elsif (required_prefix = options.delete(:require_prefix))
|
18
|
+
versions.map! { |v| "#{required_prefix}#{v}" }
|
19
|
+
defaults[:rp_prefix] = {:text => required_prefix.to_s, :required => true}
|
13
20
|
end
|
14
21
|
versions_regexp = /(#{versions.uniq.join("|")})/
|
15
22
|
raise ArgumentError, 'please provide atleast one version' if versions.empty?
|
16
23
|
options = options.deep_merge({
|
17
24
|
:constraints => {:version => versions_regexp},
|
18
25
|
:path => ':version',
|
19
|
-
:defaults =>
|
26
|
+
:defaults => defaults
|
20
27
|
})
|
21
28
|
scope options, &blk
|
22
29
|
end
|
23
30
|
alias api rocket_pants
|
24
31
|
|
32
|
+
private
|
33
|
+
|
34
|
+
def extract_rocket_pants_versions(options)
|
35
|
+
versions = (Array(options.delete(:versions)) + Array(options.delete(:version))).flatten.map(&:to_s)
|
36
|
+
versions.each do |version|
|
37
|
+
raise ArgumentError, "Got invalid version: '#{version}'" unless version =~ /\A\d+\Z/
|
38
|
+
end
|
39
|
+
versions
|
40
|
+
end
|
41
|
+
|
25
42
|
end
|
26
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocket_pants
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,232 +9,232 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
16
|
+
prerelease: false
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '3.0'
|
22
|
+
none: false
|
22
23
|
type: :runtime
|
23
|
-
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
25
|
requirements:
|
27
26
|
- - ~>
|
28
27
|
- !ruby/object:Gem::Version
|
29
28
|
version: '3.0'
|
29
|
+
none: false
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: railties
|
32
|
+
prerelease: false
|
32
33
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '3.0'
|
38
|
+
none: false
|
38
39
|
type: :runtime
|
39
|
-
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
41
|
requirements:
|
43
42
|
- - ~>
|
44
43
|
- !ruby/object:Gem::Version
|
45
44
|
version: '3.0'
|
45
|
+
none: false
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: will_paginate
|
48
|
+
prerelease: false
|
48
49
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
50
|
requirements:
|
51
51
|
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '3.0'
|
54
|
+
none: false
|
54
55
|
type: :runtime
|
55
|
-
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
57
|
requirements:
|
59
58
|
- - ~>
|
60
59
|
- !ruby/object:Gem::Version
|
61
60
|
version: '3.0'
|
61
|
+
none: false
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: hashie
|
64
|
+
prerelease: false
|
64
65
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
66
|
requirements:
|
67
67
|
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '1.0'
|
70
|
+
none: false
|
70
71
|
type: :runtime
|
71
|
-
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
73
|
requirements:
|
75
74
|
- - ~>
|
76
75
|
- !ruby/object:Gem::Version
|
77
76
|
version: '1.0'
|
77
|
+
none: false
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
79
|
name: api_smith
|
80
|
+
prerelease: false
|
80
81
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
82
|
requirements:
|
83
83
|
- - ! '>='
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
|
+
none: false
|
86
87
|
type: :runtime
|
87
|
-
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
89
|
requirements:
|
91
90
|
- - ! '>='
|
92
91
|
- !ruby/object:Gem::Version
|
93
92
|
version: '0'
|
93
|
+
none: false
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: moneta
|
96
|
+
prerelease: false
|
96
97
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
98
|
requirements:
|
99
99
|
- - ! '>='
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
|
+
none: false
|
102
103
|
type: :runtime
|
103
|
-
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
105
|
requirements:
|
107
106
|
- - ! '>='
|
108
107
|
- !ruby/object:Gem::Version
|
109
108
|
version: '0'
|
109
|
+
none: false
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
111
|
name: rspec
|
112
|
+
prerelease: false
|
112
113
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
114
|
requirements:
|
115
115
|
- - ~>
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '2.4'
|
118
|
+
none: false
|
118
119
|
type: :development
|
119
|
-
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
121
|
requirements:
|
123
122
|
- - ~>
|
124
123
|
- !ruby/object:Gem::Version
|
125
124
|
version: '2.4'
|
125
|
+
none: false
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: rspec-rails
|
128
|
+
prerelease: false
|
128
129
|
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
130
|
requirements:
|
131
131
|
- - ~>
|
132
132
|
- !ruby/object:Gem::Version
|
133
133
|
version: '2.4'
|
134
|
+
none: false
|
134
135
|
type: :development
|
135
|
-
prerelease: false
|
136
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
137
|
requirements:
|
139
138
|
- - ~>
|
140
139
|
- !ruby/object:Gem::Version
|
141
140
|
version: '2.4'
|
141
|
+
none: false
|
142
142
|
- !ruby/object:Gem::Dependency
|
143
143
|
name: rr
|
144
|
+
prerelease: false
|
144
145
|
requirement: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
146
|
requirements:
|
147
147
|
- - ~>
|
148
148
|
- !ruby/object:Gem::Version
|
149
149
|
version: '1.0'
|
150
|
+
none: false
|
150
151
|
type: :development
|
151
|
-
prerelease: false
|
152
152
|
version_requirements: !ruby/object:Gem::Requirement
|
153
|
-
none: false
|
154
153
|
requirements:
|
155
154
|
- - ~>
|
156
155
|
- !ruby/object:Gem::Version
|
157
156
|
version: '1.0'
|
157
|
+
none: false
|
158
158
|
- !ruby/object:Gem::Dependency
|
159
159
|
name: webmock
|
160
|
+
prerelease: false
|
160
161
|
requirement: !ruby/object:Gem::Requirement
|
161
|
-
none: false
|
162
162
|
requirements:
|
163
163
|
- - ! '>='
|
164
164
|
- !ruby/object:Gem::Version
|
165
165
|
version: '0'
|
166
|
+
none: false
|
166
167
|
type: :development
|
167
|
-
prerelease: false
|
168
168
|
version_requirements: !ruby/object:Gem::Requirement
|
169
|
-
none: false
|
170
169
|
requirements:
|
171
170
|
- - ! '>='
|
172
171
|
- !ruby/object:Gem::Version
|
173
172
|
version: '0'
|
173
|
+
none: false
|
174
174
|
- !ruby/object:Gem::Dependency
|
175
175
|
name: activerecord
|
176
|
+
prerelease: false
|
176
177
|
requirement: !ruby/object:Gem::Requirement
|
177
|
-
none: false
|
178
178
|
requirements:
|
179
179
|
- - ~>
|
180
180
|
- !ruby/object:Gem::Version
|
181
181
|
version: '3.0'
|
182
|
+
none: false
|
182
183
|
type: :development
|
183
|
-
prerelease: false
|
184
184
|
version_requirements: !ruby/object:Gem::Requirement
|
185
|
-
none: false
|
186
185
|
requirements:
|
187
186
|
- - ~>
|
188
187
|
- !ruby/object:Gem::Version
|
189
188
|
version: '3.0'
|
189
|
+
none: false
|
190
190
|
- !ruby/object:Gem::Dependency
|
191
|
-
name: sqlite3
|
191
|
+
name: sqlite3
|
192
|
+
prerelease: false
|
192
193
|
requirement: !ruby/object:Gem::Requirement
|
193
|
-
none: false
|
194
194
|
requirements:
|
195
195
|
- - ! '>='
|
196
196
|
- !ruby/object:Gem::Version
|
197
197
|
version: '0'
|
198
|
+
none: false
|
198
199
|
type: :development
|
199
|
-
prerelease: false
|
200
200
|
version_requirements: !ruby/object:Gem::Requirement
|
201
|
-
none: false
|
202
201
|
requirements:
|
203
202
|
- - ! '>='
|
204
203
|
- !ruby/object:Gem::Version
|
205
204
|
version: '0'
|
205
|
+
none: false
|
206
206
|
- !ruby/object:Gem::Dependency
|
207
207
|
name: reversible_data
|
208
|
+
prerelease: false
|
208
209
|
requirement: !ruby/object:Gem::Requirement
|
209
|
-
none: false
|
210
210
|
requirements:
|
211
211
|
- - ~>
|
212
212
|
- !ruby/object:Gem::Version
|
213
213
|
version: '1.0'
|
214
|
+
none: false
|
214
215
|
type: :development
|
215
|
-
prerelease: false
|
216
216
|
version_requirements: !ruby/object:Gem::Requirement
|
217
|
-
none: false
|
218
217
|
requirements:
|
219
218
|
- - ~>
|
220
219
|
- !ruby/object:Gem::Version
|
221
220
|
version: '1.0'
|
221
|
+
none: false
|
222
222
|
- !ruby/object:Gem::Dependency
|
223
223
|
name: kaminari
|
224
|
+
prerelease: false
|
224
225
|
requirement: !ruby/object:Gem::Requirement
|
225
|
-
none: false
|
226
226
|
requirements:
|
227
227
|
- - ! '>='
|
228
228
|
- !ruby/object:Gem::Version
|
229
229
|
version: '0'
|
230
|
+
none: false
|
230
231
|
type: :development
|
231
|
-
prerelease: false
|
232
232
|
version_requirements: !ruby/object:Gem::Requirement
|
233
|
-
none: false
|
234
233
|
requirements:
|
235
234
|
- - ! '>='
|
236
235
|
- !ruby/object:Gem::Version
|
237
236
|
version: '0'
|
237
|
+
none: false
|
238
238
|
description: Rocket Pants adds JSON API love to Rails and ActionController, making
|
239
239
|
it simpler to build API-oriented controllers.
|
240
240
|
email:
|
@@ -275,20 +275,17 @@ rdoc_options: []
|
|
275
275
|
require_paths:
|
276
276
|
- lib
|
277
277
|
required_ruby_version: !ruby/object:Gem::Requirement
|
278
|
-
none: false
|
279
278
|
requirements:
|
280
279
|
- - ! '>='
|
281
280
|
- !ruby/object:Gem::Version
|
282
281
|
version: '0'
|
283
|
-
segments:
|
284
|
-
- 0
|
285
|
-
hash: 1041762551203045726
|
286
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
287
282
|
none: false
|
283
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
288
284
|
requirements:
|
289
285
|
- - ! '>='
|
290
286
|
- !ruby/object:Gem::Version
|
291
287
|
version: 1.3.6
|
288
|
+
none: false
|
292
289
|
requirements: []
|
293
290
|
rubyforge_project:
|
294
291
|
rubygems_version: 1.8.24
|