rails_versioned_routing 1.3.1 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6e6570622f85cdfe8c3a6f31459f7777fb42e8a
4
- data.tar.gz: 1d19f6e6ce713b5982e6907e00dd7d83aa7348e2
3
+ metadata.gz: 4a6c823def2424d6e970bd71119a226a7c2411f0
4
+ data.tar.gz: f1f7ab31b4872bd0c28482fc443265b2e7afbb3c
5
5
  SHA512:
6
- metadata.gz: 0cba3fe8b3482655fd1bb5bf1af965944061493688c639556097dbaada76d3825ab5264fad46e454d0bb063e741cef78d782481356d325290633f3d71c13c750
7
- data.tar.gz: e59ff8061deb01535fb25f6d3806af2ea01a74b204d3b5643045e0fddf0d24f32b45247d4449f355cae3c72bef0bef70c7080c19484e539e2a20d2d66497f282
6
+ metadata.gz: f09bceb0de1ce6ccef8d6e8e3d08a982755d50230ae59288da590bd8c65c45d4fc288c7945535d5b281904ff2485ac00bc5227d9d7c33818a3575190da58b517
7
+ data.tar.gz: 01302ea4a259af0a34f7260f73013f73d58c105ba861f8f277c6db009cd5a87299a48c4ea95dd0ee292b6ce79d43d11b089303a03f5f4a3c841a710d318ffcfd
@@ -1,9 +1,23 @@
1
1
  require 'rails_versioned_routing/railtie' if defined?(Rails)
2
2
 
3
3
  module RailsVersionedRouting
4
- VERSION = "1.3.1"
4
+ VERSION = "1.4.0"
5
5
 
6
6
  class VersionConstraint
7
+ end
8
+
9
+ class BetaVersionConstraint < VersionConstraint
10
+ def matches?(request)
11
+ accept = request.headers.fetch(:accept, '*/*')
12
+ accept.match(/version=beta/)
13
+ end
14
+
15
+ def version
16
+ Float::INFINITY
17
+ end
18
+ end
19
+
20
+ class NumberedVersionConstraint < VersionConstraint
7
21
  attr_reader :version
8
22
 
9
23
  def initialize(options)
@@ -191,8 +205,13 @@ module RailsVersionedRouting
191
205
  end
192
206
  end
193
207
 
208
+ def beta!(&routes)
209
+ api_constraint = BetaVersionConstraint.new
210
+ scope(module: 'beta', constraints: api_constraint, &routes)
211
+ end
212
+
194
213
  def version(version_number, &routes)
195
- api_constraint = VersionConstraint.new(version: version_number)
214
+ api_constraint = NumberedVersionConstraint.new(version: version_number)
196
215
  scope(module: "v#{version_number}", constraints: api_constraint, &routes)
197
216
  end
198
217
 
@@ -0,0 +1,11 @@
1
+ module Beta
2
+ class SampleController < ApplicationController
3
+ def a_path_overridden_from_v1
4
+ render text: 'beta'
5
+ end
6
+
7
+ def a_path_only_in_beta
8
+ render text: 'beta'
9
+ end
10
+ end
11
+ end
@@ -3,6 +3,11 @@ require 'rails_versioned_routing'
3
3
  Dummy::Application.routes.draw do
4
4
  extend RailsVersionedRouting
5
5
 
6
+ beta! do
7
+ get 'a_path_overridden_from_v1/:id/whats/:ok', controller: 'sample', action: 'a_path_overridden_from_v1'
8
+ get 'a_path_only_in_beta', controller: 'sample'
9
+ end
10
+
6
11
  version(3) do
7
12
  post 'a_path_only_in_v3', controller: 'sample', action: 'posted_a_path_only_in_v3'
8
13
  get 'a_path_only_in_v3', controller: 'sample'
Binary file