versioncake 1.3.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/Appraisals +6 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +4 -4
- data/README.md +65 -30
- data/RELEASE.md +1 -1
- data/bin/versioncake +9 -0
- data/gemfiles/rails3.2.gemfile.lock +6 -2
- data/gemfiles/rails4.0.gemfile.lock +1 -1
- data/gemfiles/rails4.1.gemfile +9 -0
- data/gemfiles/rails4.1.gemfile.lock +87 -0
- data/lib/versioncake/cli.rb +60 -0
- data/lib/versioncake/configuration.rb +21 -21
- data/lib/versioncake/railtie.rb +3 -19
- data/lib/versioncake/strategies/extraction_strategy.rb +5 -5
- data/lib/versioncake/strategies/http_accept_parameter_strategy.rb +1 -1
- data/lib/versioncake/strategies/http_header_strategy.rb +2 -2
- data/lib/versioncake/strategies/path_parameter_strategy.rb +11 -0
- data/lib/versioncake/strategies/query_parameter_strategy.rb +2 -2
- data/lib/versioncake/strategies/request_parameter_strategy.rb +2 -2
- data/lib/versioncake/version.rb +1 -1
- data/lib/versioncake/versioned_request.rb +10 -6
- data/lib/versioncake/view_additions.rb +67 -10
- data/lib/versioncake.rb +2 -0
- data/test/{fixtures/templates/versioned.v1.html.erb → app/views/renders/index.html.v1.erb} +0 -0
- data/test/{fixtures/templates/versioned.v2.html.erb → app/views/renders/index.html.v2.erb} +0 -0
- data/test/config/application.rb +3 -2
- data/test/fixtures/templates/v1_extension_scheme.v3.html.erb +7 -0
- data/test/fixtures/templates/v1_extension_scheme.v6.json +4 -0
- data/test/fixtures/templates/versioned.html.v1.erb +1 -0
- data/test/fixtures/templates/versioned.html.v2.erb +1 -0
- data/test/fixtures/templates/{versioned.v3.html.erb → versioned.html.v3.erb} +0 -0
- data/test/fixtures/test_cases.yml +70 -0
- data/test/functional/custom_strategy_controller_test.rb +16 -0
- data/test/functional/multiple_strategy_controller_test.rb +24 -0
- data/test/functional/renders_controller_test.rb +14 -168
- data/test/functional/strategy_controller_test.rb +37 -0
- data/test/unit/cli_test.rb +48 -0
- data/test/unit/configuration_test.rb +15 -19
- data/test/unit/strategies/extraction_strategy_test.rb +2 -2
- data/test/unit/strategies/path_parameter_strategy_test.rb +17 -0
- data/test/unit/strategies/query_parameter_strategy_test.rb +5 -0
- data/test/unit/versioned_request_test.rb +1 -1
- data/test/unit/view_additions_test.rb +35 -0
- data/versioncake.gemspec +1 -0
- metadata +25 -9
- data/test/app/views/renders/index.v1.html.erb +0 -1
- data/test/app/views/renders/index.v2.html.erb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fbcc57e744a93f5f6de3774d76ac1243a7fa412
|
4
|
+
data.tar.gz: a928bce4aaf76fa1bfd130773b1e7f8bd4b85727
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e1bd9d2d1206d7ac5f036ff4b58ac6ef5bc218eb86a11319efa7a93dcb341a8ce1760740be620fbef9ca0b205dd067e414ae0f06c22c28b38851a746ad8b661
|
7
|
+
data.tar.gz: 77692e1b0088daa052cbca53d4da0f35acbac818d7e7e0277df12111eeafb6f0592f05e10faccb8ba6dcd78ecd261a7e45dea494c101eb7d53abe3edb999fbb7
|
data/.travis.yml
CHANGED
@@ -2,16 +2,21 @@ language: ruby
|
|
2
2
|
rvm:
|
3
3
|
- 1.9.2
|
4
4
|
- 1.9.3
|
5
|
+
- 2.0.0
|
6
|
+
- 2.1.0
|
5
7
|
- ruby-head
|
6
8
|
|
7
9
|
gemfile:
|
8
10
|
- gemfiles/rails3.2.gemfile
|
9
11
|
- gemfiles/rails4.0.gemfile
|
12
|
+
- gemfiles/rails4.1.gemfile
|
10
13
|
|
11
14
|
matrix:
|
12
15
|
exclude:
|
13
16
|
- rvm: 1.9.2
|
14
17
|
gemfile: gemfiles/rails4.0.gemfile
|
18
|
+
- rvm: 1.9.2
|
19
|
+
gemfile: gemfiles/rails4.1.gemfile
|
15
20
|
|
16
21
|
allow_failures:
|
17
22
|
- rvm: ruby-head
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
[Full Changelog](https://github.com/bwillis/versioncake/compare/v1.3...master)
|
4
4
|
|
5
|
+
Bug Fixes:
|
6
|
+
|
7
|
+
* Adjusting view details priorities so that RABL templates that do not have a format are not prioritized over templates that do have a format (issues #14). This is going to go into v2 as it is a breaking change.
|
8
|
+
* Looking up a versioned or unversioned layout template was not working (issue #22). The change related to issue #14 resulted in the template format not being identified properly. Monkey patched another Rails (for old and new Rails) method to fix this issue.
|
9
|
+
|
10
|
+
Enhancements:
|
11
|
+
|
12
|
+
* New path strategy to support `/v3/posts` style versioning, thanks [Michael Elfassy](https://github.com/elfassy)
|
13
|
+
* Support Rails 4.1, thanks [Washington L Braga Jr](https://github.com/huoxito)
|
14
|
+
* Added v1->v2 template renaming migration script
|
15
|
+
* Improving configuration
|
16
|
+
|
5
17
|
## 1.3.0 (Sept 26, 2013)
|
6
18
|
|
7
19
|
[Full Changelog](https://github.com/bwillis/versioncake/compare/v1.2...v1.3)
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
versioncake (
|
4
|
+
versioncake (2.0.0)
|
5
5
|
actionpack (>= 3.2)
|
6
6
|
activesupport (>= 3.2)
|
7
7
|
railties (>= 3.2)
|
@@ -25,7 +25,7 @@ GEM
|
|
25
25
|
appraisal (0.5.2)
|
26
26
|
bundler
|
27
27
|
rake
|
28
|
-
atomic (1.1.
|
28
|
+
atomic (1.1.14)
|
29
29
|
builder (3.1.4)
|
30
30
|
colorize (0.5.8)
|
31
31
|
coveralls (0.6.7)
|
@@ -35,7 +35,7 @@ GEM
|
|
35
35
|
simplecov (>= 0.7)
|
36
36
|
thor
|
37
37
|
erubis (2.7.0)
|
38
|
-
i18n (0.6.
|
38
|
+
i18n (0.6.9)
|
39
39
|
metaclass (0.0.1)
|
40
40
|
mime-types (1.23)
|
41
41
|
minitest (4.7.5)
|
@@ -59,7 +59,7 @@ GEM
|
|
59
59
|
simplecov-html (0.7.1)
|
60
60
|
test-unit (2.5.5)
|
61
61
|
thor (0.18.1)
|
62
|
-
thread_safe (0.1.
|
62
|
+
thread_safe (0.1.3)
|
63
63
|
atomic
|
64
64
|
tzinfo (0.3.37)
|
65
65
|
|
data/README.md
CHANGED
@@ -14,10 +14,10 @@ Version Cake is an unobtrusive way to version APIs in your Rails app.
|
|
14
14
|
|
15
15
|
```ruby
|
16
16
|
app/views/posts/
|
17
|
-
- index.v1.
|
18
|
-
- index.v3.
|
19
|
-
- index.v1.
|
20
|
-
- index.v4.
|
17
|
+
- index.xml.v1.builder
|
18
|
+
- index.xml.v3.builder
|
19
|
+
- index.json.v1.jbuilder
|
20
|
+
- index.json.v4.jbuilder
|
21
21
|
```
|
22
22
|
- Gracefully degrade requests to the latest supported version
|
23
23
|
- Clients can request API versions through different strategies
|
@@ -33,7 +33,35 @@ gem install versioncake
|
|
33
33
|
|
34
34
|
### Requirements
|
35
35
|
|
36
|
-
Rails
|
36
|
+
| Version | Rails 3.2 Support? | Rails 4 Support? | Rails 4.1 Support? |
|
37
|
+
| ------- |:---------:| -------:| -------:|
|
38
|
+
| 1.0 | Yes | No | No |
|
39
|
+
| 1.1 | Yes | No | No |
|
40
|
+
| 1.2 | Yes | Yes | No |
|
41
|
+
| 1.3 | Yes | Yes | No |
|
42
|
+
| 2.0 | Yes | Yes | Yes |
|
43
|
+
|
44
|
+
## Upgrade v1.0 -> v2.0
|
45
|
+
|
46
|
+
### Filename changes
|
47
|
+
The major breaking change to require a bump to v2.0 was the order of the extensions. To avoid priority issues with the format (#14), the version number and the format have been swapped.
|
48
|
+
|
49
|
+
`index.v1.json.jbuilder` -> `index.json.v1.jbuilder`
|
50
|
+
|
51
|
+
To make it easier to upgrade, run the following command to automatically rename these files:
|
52
|
+
|
53
|
+
`verisoncake migrate` or `verisoncake migrate path/to/views`
|
54
|
+
|
55
|
+
### Configuration changes
|
56
|
+
|
57
|
+
The configuration options for Version Cake have been namespaced and slightly renamed. The following is a mapping of the old names to the new names:
|
58
|
+
|
59
|
+
| Old Name | New Name |
|
60
|
+
| --------------------------------------- | -------------------------------------------- |
|
61
|
+
| config.view_versions | config.versioncake.supported_version_numbers |
|
62
|
+
| config.view_version_extraction_strategy | config.versioncake.extraction_strategy |
|
63
|
+
| config.view_version_string | config.versioncake.version_key |
|
64
|
+
| config.default_version | config.versioncake.default_version |
|
37
65
|
|
38
66
|
## Example
|
39
67
|
|
@@ -41,8 +69,8 @@ In this simple example we will outline the code that is introduced to support a
|
|
41
69
|
|
42
70
|
### config/application.rb
|
43
71
|
```ruby
|
44
|
-
config.
|
45
|
-
config.
|
72
|
+
config.versioncake.supported_version_numbers = (1...4)
|
73
|
+
config.versioncake.extraction_strategy = :query_parameter # for simplicity
|
46
74
|
```
|
47
75
|
|
48
76
|
Often times with APIs, depending upon the version, different logic needs to be applied. With the following controller code, the initial value of @posts includes all Post entries.
|
@@ -65,21 +93,21 @@ class PostsController < ApplicationController
|
|
65
93
|
end
|
66
94
|
```
|
67
95
|
|
68
|
-
See the view samples below. The basic top level posts are referenced in views/posts/index.v1.
|
69
|
-
But for views/posts/index.v4.
|
96
|
+
See the view samples below. The basic top level posts are referenced in views/posts/index.json.v1.jbuilder.
|
97
|
+
But for views/posts/index.json.v4.jbuilder, we utilize the additional related comments.
|
70
98
|
|
71
99
|
### Views
|
72
100
|
|
73
101
|
Notice the version numbers are denoted by the "v{version number}" extension within the file name.
|
74
102
|
|
75
|
-
#### views/posts/index.v1.
|
103
|
+
#### views/posts/index.json.v1.jbuilder
|
76
104
|
```ruby
|
77
105
|
json.array!(@posts) do |json, post|
|
78
106
|
json.(post, :id, :title)
|
79
107
|
end
|
80
108
|
```
|
81
109
|
|
82
|
-
#### views/posts/index.v4.
|
110
|
+
#### views/posts/index.json.v4.jbuilder
|
83
111
|
```ruby
|
84
112
|
json.array!(@posts) do |json, post|
|
85
113
|
json.(post, :id, :title)
|
@@ -89,7 +117,7 @@ end
|
|
89
117
|
|
90
118
|
### Sample Output
|
91
119
|
|
92
|
-
When a version is specified for which a view doesn't exist, the request degrades and renders the next lowest version number to ensure the API's backwards compatibility. In the following case, since views/posts/index.v3.
|
120
|
+
When a version is specified for which a view doesn't exist, the request degrades and renders the next lowest version number to ensure the API's backwards compatibility. In the following case, since views/posts/index.json.v3.jbuilder doesn't exist, views/posts/index.json.v1.jbuilder is rendered instead.
|
93
121
|
|
94
122
|
#### http://localhost:3000/posts.json?api_version=3
|
95
123
|
```javascript
|
@@ -110,7 +138,7 @@ When a version is specified for which a view doesn't exist, the request degrades
|
|
110
138
|
```
|
111
139
|
|
112
140
|
|
113
|
-
For a given request, if we specify the version number, and that version of the view exists, that version specific view version will be rendered. In the below case, views/posts/index.v1.
|
141
|
+
For a given request, if we specify the version number, and that version of the view exists, that version specific view version will be rendered. In the below case, views/posts/index.json.v1.jbuilder is rendered.
|
114
142
|
|
115
143
|
#### http://localhost:3000/posts.json?api_version=2 or http://localhost:3000/posts.json?api_version=1
|
116
144
|
```javascript
|
@@ -131,7 +159,7 @@ For a given request, if we specify the version number, and that version of the v
|
|
131
159
|
```
|
132
160
|
|
133
161
|
|
134
|
-
When no version is specified, the latest version of the view is rendered. In this case, views/posts/index.v4.
|
162
|
+
When no version is specified, the latest version of the view is rendered. In this case, views/posts/index.json.v4.jbuilder.
|
135
163
|
|
136
164
|
#### http://localhost:3000/posts.json
|
137
165
|
```javascript
|
@@ -172,35 +200,39 @@ The configuration should be placed in your Rails projects `config/application.rb
|
|
172
200
|
You need to define the supported versions in your Rails application.rb file as `view_versions`. Use this config to set the range of supported API versions that can be served:
|
173
201
|
|
174
202
|
```ruby
|
175
|
-
config.
|
203
|
+
config.versioncake.supported_version_numbers = [1,2,3,4,5] # or (1..5)
|
176
204
|
```
|
177
205
|
|
178
206
|
#### Extraction Strategy
|
179
207
|
|
180
208
|
You can also define the way to extract the version. The `view_version_extraction_strategy` allows you to set one of the default strategies or provide a proc to set your own. You can also pass it a prioritized array of the strategies.
|
181
209
|
```ruby
|
182
|
-
config.
|
210
|
+
config.versioncake.extraction_strategy = :query_parameter # [:http_header, :http_accept_parameter]
|
183
211
|
```
|
184
212
|
These are the available strategies:
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
213
|
+
|
214
|
+
Strategy | Description | Example
|
215
|
+
--- | --- | ---
|
216
|
+
:query_parameter | version in the url query parameter, for testing or to override for special case | `http://localhost:3000/posts.json?api_version=1` (This is the default.)
|
217
|
+
:path_parameter | version in the url path parameter | `api/v:api_version/`
|
218
|
+
request_parameter | version that is sent in the body of the request | Good for testing.
|
219
|
+
:http_header | Api version HTTP header | `X-API-Version: 1`
|
220
|
+
:http_accept_parameter | HTTP Accept header | `Accept: application/xml; version=1` [why do this?](http://blog.steveklabnik.com/posts/2011-07-03-nobody-understands-rest-or-http#i_want_my_api_to_be_versioned)
|
221
|
+
custom | takes the request object and must return an integer | lambda {|request| request.headers["HTTP_X_MY_VERSION"].to_i }
|
190
222
|
|
191
223
|
|
192
224
|
#### Default Version
|
193
225
|
|
194
226
|
When no version is supplied by a client, the version rendered will be the latest version by default. If you want to override this to another version, set the following property:
|
195
227
|
```ruby
|
196
|
-
config.default_version = 4
|
228
|
+
config.versioncake.default_version = 4
|
197
229
|
```
|
198
230
|
|
199
231
|
#### Version String
|
200
232
|
|
201
233
|
The extraction strategies use a default string key of `api_version`, but that can be changed:
|
202
234
|
```ruby
|
203
|
-
config.
|
235
|
+
config.versioncake.version_key = "special_version_parameter_name"
|
204
236
|
```
|
205
237
|
|
206
238
|
### Version your views
|
@@ -213,8 +245,8 @@ When a client makes a request to your controller the latest version of the view
|
|
213
245
|
- edit.html.erb
|
214
246
|
- show.html.erb
|
215
247
|
- show.json.jbuilder
|
216
|
-
- show.v1.
|
217
|
-
- show.v2.
|
248
|
+
- show.json.v1.jbuilder
|
249
|
+
- show.json.v2.jbuilder
|
218
250
|
- new.html.erb
|
219
251
|
- _form.html.erb
|
220
252
|
```
|
@@ -248,7 +280,7 @@ Testing can be painful but here are some easy ways to test different versions of
|
|
248
280
|
Allowing more extraction strategies during testing can be helpful when needing to override the version.
|
249
281
|
```ruby
|
250
282
|
# config/environments/test.rb
|
251
|
-
config.
|
283
|
+
config.versioncake.extraction_strategy = [:query_parameter, :request_parameter, :http_header, :http_accept_parameter]
|
252
284
|
```
|
253
285
|
|
254
286
|
### Testing a specific version
|
@@ -265,23 +297,23 @@ You can also test a specific version through a specific strategy such query_para
|
|
265
297
|
# test/functional/renders_controller_test.rb#L47
|
266
298
|
test "render version 1 of the partial based on the parameter _api_version" do
|
267
299
|
get :index, "api_version" => "1"
|
268
|
-
assert_equal @response.body, "index.v1.
|
300
|
+
assert_equal @response.body, "index.html.v1.erb"
|
269
301
|
end
|
270
302
|
```
|
271
303
|
|
272
304
|
### Testing all supported versions
|
273
305
|
|
274
|
-
You can iterate over all of the supported version numbers by accessing the ```AppName::Application.config.
|
306
|
+
You can iterate over all of the supported version numbers by accessing the ```AppName::Application.config.versioncake.supported_version_numbers```.
|
275
307
|
|
276
308
|
```ruby
|
277
|
-
AppName::Application.config.
|
309
|
+
AppName::Application.config.versioncake.supported_version_numbers.each do |supported_version|
|
278
310
|
before do
|
279
311
|
@controller.stubs(:requested_version).returns(supported_version)
|
280
312
|
end
|
281
313
|
|
282
314
|
test "all versions render the correct template" do
|
283
315
|
get :index
|
284
|
-
assert_equal @response.body, "index.v1.
|
316
|
+
assert_equal @response.body, "index.html.v1.erb"
|
285
317
|
end
|
286
318
|
end
|
287
319
|
```
|
@@ -296,6 +328,9 @@ Thanks to all those who have helped make Version Cake really sweet:
|
|
296
328
|
* Sevag
|
297
329
|
* [Billy](https://github.com/bcatherall)
|
298
330
|
* [Jérémie Meyer de Ville](https://github.com/jeremiemv)
|
331
|
+
* [Michael Elfassy](https://github.com/elfassy)
|
332
|
+
* [Kelley Reynolds](https://github.com/kreynolds)
|
333
|
+
* [Washington L Braga Jr](https://github.com/huoxito)
|
299
334
|
|
300
335
|
# Related Material
|
301
336
|
|
data/RELEASE.md
CHANGED
@@ -23,5 +23,5 @@ Keeping releases consistent is important so here are the steps to follow when pu
|
|
23
23
|
7. Tag the version ```git tag -a vX.X -m 'Version X.X Stable' && git push --tags```
|
24
24
|
|
25
25
|
8. Build the gem ```gem build versioncake.gemspec```
|
26
|
-
9. Push the gem to ruby gems ```gem push versioncake-
|
26
|
+
9. Push the gem to ruby gems ```gem push versioncake-X.X.X.gem```
|
27
27
|
10. Remove the built gem locally ```rm versioncake-X.X.X.gem```
|
data/bin/versioncake
ADDED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../
|
3
3
|
specs:
|
4
|
-
versioncake (
|
4
|
+
versioncake (2.0.0)
|
5
5
|
actionpack (>= 3.2)
|
6
6
|
activesupport (>= 3.2)
|
7
7
|
railties (>= 3.2)
|
@@ -29,6 +29,7 @@ GEM
|
|
29
29
|
appraisal (0.5.2)
|
30
30
|
bundler
|
31
31
|
rake
|
32
|
+
atomic (1.1.14)
|
32
33
|
builder (3.0.4)
|
33
34
|
colorize (0.5.8)
|
34
35
|
coveralls (0.6.7)
|
@@ -77,8 +78,11 @@ GEM
|
|
77
78
|
tilt (~> 1.1, != 1.3.0)
|
78
79
|
test-unit (2.5.5)
|
79
80
|
thor (0.18.1)
|
81
|
+
thread_safe (0.1.3)
|
82
|
+
atomic
|
80
83
|
tilt (1.4.1)
|
81
|
-
tzinfo (
|
84
|
+
tzinfo (1.1.0)
|
85
|
+
thread_safe (~> 0.1)
|
82
86
|
|
83
87
|
PLATFORMS
|
84
88
|
ruby
|
@@ -0,0 +1,87 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
versioncake (2.0.0)
|
5
|
+
actionpack (>= 3.2)
|
6
|
+
activesupport (>= 3.2)
|
7
|
+
railties (>= 3.2)
|
8
|
+
tzinfo
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
actionpack (4.1.0.beta1)
|
14
|
+
actionview (= 4.1.0.beta1)
|
15
|
+
activesupport (= 4.1.0.beta1)
|
16
|
+
rack (~> 1.5.2)
|
17
|
+
rack-test (~> 0.6.2)
|
18
|
+
actionview (4.1.0.beta1)
|
19
|
+
activesupport (= 4.1.0.beta1)
|
20
|
+
builder (~> 3.1)
|
21
|
+
erubis (~> 2.7.0)
|
22
|
+
activesupport (4.1.0.beta1)
|
23
|
+
i18n (~> 0.6, >= 0.6.9)
|
24
|
+
json (~> 1.7, >= 1.7.7)
|
25
|
+
minitest (~> 5.1)
|
26
|
+
thread_safe (~> 0.1)
|
27
|
+
tzinfo (~> 1.1)
|
28
|
+
appraisal (0.5.2)
|
29
|
+
bundler
|
30
|
+
rake
|
31
|
+
atomic (1.1.14)
|
32
|
+
builder (3.2.2)
|
33
|
+
coveralls (0.7.0)
|
34
|
+
multi_json (~> 1.3)
|
35
|
+
rest-client
|
36
|
+
simplecov (>= 0.7)
|
37
|
+
term-ansicolor
|
38
|
+
thor
|
39
|
+
docile (1.1.2)
|
40
|
+
erubis (2.7.0)
|
41
|
+
i18n (0.6.9)
|
42
|
+
json (1.8.1)
|
43
|
+
metaclass (0.0.2)
|
44
|
+
mime-types (2.0)
|
45
|
+
minitest (5.2.1)
|
46
|
+
mocha (1.0.0)
|
47
|
+
metaclass (~> 0.0.1)
|
48
|
+
multi_json (1.8.4)
|
49
|
+
rack (1.5.2)
|
50
|
+
rack-test (0.6.2)
|
51
|
+
rack (>= 1.0)
|
52
|
+
railties (4.1.0.beta1)
|
53
|
+
actionpack (= 4.1.0.beta1)
|
54
|
+
activesupport (= 4.1.0.beta1)
|
55
|
+
rake (>= 0.8.7)
|
56
|
+
thor (>= 0.18.1, < 2.0)
|
57
|
+
rake (10.1.1)
|
58
|
+
rest-client (1.6.7)
|
59
|
+
mime-types (>= 1.16)
|
60
|
+
simplecov (0.8.2)
|
61
|
+
docile (~> 1.1.0)
|
62
|
+
multi_json
|
63
|
+
simplecov-html (~> 0.8.0)
|
64
|
+
simplecov-html (0.8.0)
|
65
|
+
term-ansicolor (1.2.2)
|
66
|
+
tins (~> 0.8)
|
67
|
+
test-unit (2.5.5)
|
68
|
+
thor (0.18.1)
|
69
|
+
thread_safe (0.1.3)
|
70
|
+
atomic
|
71
|
+
tins (0.13.1)
|
72
|
+
tzinfo (1.1.0)
|
73
|
+
thread_safe (~> 0.1)
|
74
|
+
|
75
|
+
PLATFORMS
|
76
|
+
ruby
|
77
|
+
|
78
|
+
DEPENDENCIES
|
79
|
+
actionpack (~> 4.1.0.beta1)
|
80
|
+
activesupport (~> 4.1.0.beta1)
|
81
|
+
appraisal
|
82
|
+
coveralls
|
83
|
+
mocha
|
84
|
+
railties (~> 4.1.0.beta1)
|
85
|
+
rake
|
86
|
+
test-unit
|
87
|
+
versioncake!
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module VersionCake
|
2
|
+
class Cli
|
3
|
+
RAILS_VIEW_PATH = 'app/views'
|
4
|
+
HANDLERS = %w(
|
5
|
+
haml
|
6
|
+
erb
|
7
|
+
jbuilder
|
8
|
+
rabl
|
9
|
+
builder
|
10
|
+
)
|
11
|
+
|
12
|
+
def migrate(path)
|
13
|
+
path = RAILS_VIEW_PATH unless path
|
14
|
+
raise ArgumentError.new("No directory exists for '#{path}'") unless File.exists? path
|
15
|
+
|
16
|
+
files_to_rename = []
|
17
|
+
Dir.glob(File.join(path, '**/*.*')).each do |filename|
|
18
|
+
if has_version_in_name?(filename) && new_name = v1_to_v2_filename(filename)
|
19
|
+
files_to_rename << [filename, new_name]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
if files_to_rename.empty?
|
24
|
+
puts 'No files to rename'
|
25
|
+
end
|
26
|
+
|
27
|
+
files_to_rename.each do |names|
|
28
|
+
old_name, new_name = names
|
29
|
+
puts "Renaming #{old_name} to #{new_name}"
|
30
|
+
File.rename(old_name, new_name)
|
31
|
+
end
|
32
|
+
|
33
|
+
files_to_rename
|
34
|
+
end
|
35
|
+
|
36
|
+
def v1_to_v2_filename(path)
|
37
|
+
filename = File.basename(path)
|
38
|
+
if m = filename.match(/(\.v[0-9]+)/)
|
39
|
+
version_str = m[0]
|
40
|
+
new_path = path.sub version_str, ''
|
41
|
+
|
42
|
+
if new_path.end_with? *HANDLERS
|
43
|
+
# handler exists at the end, need to put the version before it
|
44
|
+
parts = new_path.split('.')
|
45
|
+
new_path = parts.insert(parts.length-1, version_str.delete('.')).join('.')
|
46
|
+
else
|
47
|
+
# no handler, version is the last extension
|
48
|
+
new_path << version_str
|
49
|
+
end
|
50
|
+
|
51
|
+
path != new_path ? new_path : nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def has_version_in_name?(filename)
|
56
|
+
filename =~ /v[0-9]+/
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -2,47 +2,47 @@ require 'active_support/core_ext/module/attribute_accessors.rb'
|
|
2
2
|
require 'active_support/core_ext/array/wrap.rb'
|
3
3
|
|
4
4
|
module VersionCake
|
5
|
-
|
5
|
+
class Configuration
|
6
6
|
|
7
7
|
SUPPORTED_VERSIONS_DEFAULT = (1..10)
|
8
|
+
VERSION_KEY_DEFAULT = 'api_version'
|
8
9
|
|
9
|
-
|
10
|
+
attr_reader :extraction_strategies, :supported_version_numbers
|
11
|
+
attr_accessor :default_version, :version_key
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
def initialize
|
14
|
+
@version_key = VERSION_KEY_DEFAULT
|
15
|
+
self.supported_version_numbers = SUPPORTED_VERSIONS_DEFAULT
|
16
|
+
self.extraction_strategy = :query_parameter
|
17
|
+
end
|
16
18
|
|
17
|
-
def
|
18
|
-
|
19
|
+
def extraction_strategy=(val)
|
20
|
+
@extraction_strategies = []
|
19
21
|
Array.wrap(val).each do |configured_strategy|
|
20
|
-
|
22
|
+
@extraction_strategies << VersionCake::ExtractionStrategy.lookup(configured_strategy)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
26
|
+
def supported_version_numbers=(val)
|
27
|
+
@supported_version_numbers = val.respond_to?(:to_a) ? val.to_a : Array.wrap(val)
|
28
|
+
@supported_version_numbers.sort!.reverse!
|
27
29
|
end
|
28
30
|
|
29
|
-
def
|
30
|
-
supported_version_numbers.collect do |supported_version_number|
|
31
|
+
def supported_versions(requested_version_number=nil)
|
32
|
+
@supported_version_numbers.collect do |supported_version_number|
|
31
33
|
if requested_version_number.nil? || supported_version_number <= requested_version_number
|
32
34
|
:"v#{supported_version_number}"
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
37
|
-
def
|
38
|
-
supported_version_numbers.include? version
|
39
|
+
def supports_version?(version)
|
40
|
+
@supported_version_numbers.include? version
|
39
41
|
end
|
40
42
|
|
41
|
-
def
|
42
|
-
supported_version_numbers.first
|
43
|
+
def latest_version
|
44
|
+
@supported_version_numbers.first
|
43
45
|
end
|
44
46
|
|
45
|
-
self.extraction_strategy = :query_parameter
|
46
|
-
self.supported_version_numbers = SUPPORTED_VERSIONS_DEFAULT
|
47
47
|
end
|
48
48
|
end
|
data/lib/versioncake/railtie.rb
CHANGED
@@ -1,23 +1,7 @@
|
|
1
1
|
require 'rails'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
if app.config.respond_to?(:view_versions)
|
7
|
-
VersionCake::Configuration.supported_version_numbers = app.config.view_versions
|
8
|
-
end
|
9
|
-
|
10
|
-
if app.config.respond_to?(:view_version_extraction_strategy)
|
11
|
-
VersionCake::Configuration.extraction_strategy = app.config.view_version_extraction_strategy
|
12
|
-
end
|
13
|
-
|
14
|
-
if app.config.respond_to?(:view_version_string)
|
15
|
-
VersionCake::ExtractionStrategy.version_string = app.config.view_version_string
|
16
|
-
end
|
17
|
-
|
18
|
-
if app.config.respond_to?(:default_version)
|
19
|
-
VersionCake::Configuration.default_version = app.config.default_version
|
20
|
-
end
|
21
|
-
end
|
3
|
+
module VersionCake
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
config.versioncake = VersionCake::Configuration.new
|
22
6
|
end
|
23
7
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require 'active_support/core_ext/class/attribute_accessors.rb'
|
2
1
|
require 'active_support/core_ext/string/inflections.rb'
|
3
2
|
|
4
3
|
module VersionCake
|
5
4
|
class ExtractionStrategy
|
6
5
|
|
7
|
-
cattr_accessor :version_string
|
8
|
-
@@version_string = 'api_version'
|
9
|
-
|
10
6
|
def extract(request)
|
11
7
|
version = execute(request)
|
12
|
-
return version.to_i if version
|
8
|
+
return version.to_i if version && /[0-9]+/.match(version)
|
9
|
+
end
|
10
|
+
|
11
|
+
def version_key
|
12
|
+
VersionCake::Railtie.config.versioncake.version_key
|
13
13
|
end
|
14
14
|
|
15
15
|
def execute(request)
|