api_versioner 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +51 -0
- data/.reek.yml +13 -1
- data/.rubocop.yml +4 -1
- data/CHANGELOG.md +6 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +43 -57
- data/api_versioner.gemspec +2 -12
- data/lib/api_versioner/client_version_middleware.rb +13 -6
- data/lib/api_versioner/configuration.rb +17 -10
- data/lib/api_versioner/default_policy.rb +2 -2
- data/lib/api_versioner/railtie.rb +3 -3
- data/lib/api_versioner/semantic_version.rb +130 -0
- data/lib/api_versioner/server_version_middleware.rb +4 -6
- data/lib/api_versioner/version.rb +1 -1
- data/lib/api_versioner.rb +1 -0
- metadata +12 -128
- data/CHANGELOG +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '099f96ae4e782a74607dff5ad091812122c38fe357aa3b43f0855f5151f0b2ca'
|
4
|
+
data.tar.gz: 9031bfd2060c4261016afead3e8176070de20e9440c3fd8a3ff736cd3976488f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3ee3f818f676a23ae7f10adcc23dc166a9e7a53fdaf2aa6a13a9a986c95fef864182298311d000215e27d55228cf9dbacd67f8a89dceb9e371d078a5f9bcd4e
|
7
|
+
data.tar.gz: 7f116ae279a36d826735662f33c2693535f692c6b27531c703a5745eb660b2adf98c4e31006fea3e8550a54d81d359744fb90d35f986f5c3a18aaccc0d37a099
|
@@ -0,0 +1,51 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
- push
|
5
|
+
- pull_request
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
|
10
|
+
runs-on: ubuntu-22.04
|
11
|
+
name: Ruby ${{ matrix.ruby }}
|
12
|
+
strategy:
|
13
|
+
fail-fast: false
|
14
|
+
matrix:
|
15
|
+
include:
|
16
|
+
# https://github.com/ruby/ruby-builder/releases
|
17
|
+
- ruby: "head"
|
18
|
+
- ruby: "3.2"
|
19
|
+
- ruby: "3.1"
|
20
|
+
- ruby: "3.0"
|
21
|
+
- ruby: "2.7"
|
22
|
+
- ruby: "2.6"
|
23
|
+
- ruby: "jruby-9.4.2"
|
24
|
+
- ruby: "truffleruby-22.3.1"
|
25
|
+
|
26
|
+
env:
|
27
|
+
BUNDLE_GEMFILE: Gemfile
|
28
|
+
|
29
|
+
steps:
|
30
|
+
# https://github.com/actions/checkout
|
31
|
+
- uses: actions/checkout@v3
|
32
|
+
|
33
|
+
# https://github.com/ruby/setup-ruby
|
34
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
35
|
+
uses: ruby/setup-ruby@v1
|
36
|
+
with:
|
37
|
+
ruby-version: ${{ matrix.ruby }}
|
38
|
+
bundler-cache: true
|
39
|
+
|
40
|
+
# Check code standards only for latest MRI. It takes a lot of time for jruby or truffleruby
|
41
|
+
- name: Check Code Standards
|
42
|
+
if: startsWith(matrix.ruby, '3.2')
|
43
|
+
run: bundle exec rubocop
|
44
|
+
|
45
|
+
# Check code smells
|
46
|
+
- name: Check Code Standards
|
47
|
+
if: startsWith(matrix.ruby, '3.2')
|
48
|
+
run: bundle exec reek
|
49
|
+
|
50
|
+
- name: Run Tests
|
51
|
+
run: bundle exec rspec
|
data/.reek.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -10,6 +10,9 @@ AllCops:
|
|
10
10
|
- bin/*
|
11
11
|
- vendor/**/*
|
12
12
|
|
13
|
+
Gemspec/RequireMFA:
|
14
|
+
Enabled: false
|
15
|
+
|
13
16
|
Layout/ArgumentAlignment:
|
14
17
|
EnforcedStyle: with_fixed_indentation
|
15
18
|
|
@@ -59,7 +62,7 @@ RSpec/ScatteredSetup:
|
|
59
62
|
- spec/integration/**/*
|
60
63
|
|
61
64
|
RSpec/VariableName:
|
62
|
-
|
65
|
+
AllowedPatterns:
|
63
66
|
- Authorization
|
64
67
|
|
65
68
|
Style/Documentation:
|
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
@@ -4,3 +4,10 @@ source 'https://rubygems.org'
|
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in versioner.gemspec
|
6
6
|
gemspec
|
7
|
+
|
8
|
+
gem 'reek', '~> 6.0'
|
9
|
+
gem 'rspec', '~> 3.12.0'
|
10
|
+
gem 'rubocop', '~> 1.4'
|
11
|
+
gem 'rubocop-performance', '~> 1.5', '>= 1.5.2'
|
12
|
+
gem 'rubocop-rspec', '~> 2.0'
|
13
|
+
gem 'simplecov', '~> 0.22.0'
|
data/Gemfile.lock
CHANGED
@@ -1,95 +1,81 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
api_versioner (1.
|
5
|
-
semantic (~> 1.6.1)
|
4
|
+
api_versioner (1.2.0)
|
6
5
|
|
7
6
|
GEM
|
8
7
|
remote: https://rubygems.org/
|
9
8
|
specs:
|
10
|
-
activesupport (6.1.4.1)
|
11
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
-
i18n (>= 1.6, < 2)
|
13
|
-
minitest (>= 5.1)
|
14
|
-
tzinfo (~> 2.0)
|
15
|
-
zeitwerk (~> 2.3)
|
16
9
|
ast (2.4.2)
|
17
|
-
|
18
|
-
diff-lcs (1.4.4)
|
10
|
+
diff-lcs (1.5.0)
|
19
11
|
docile (1.4.0)
|
20
|
-
|
21
|
-
|
12
|
+
json (2.6.3)
|
13
|
+
json (2.6.3-java)
|
22
14
|
kwalify (0.7.2)
|
23
|
-
|
24
|
-
|
25
|
-
parser (3.0.2.0)
|
15
|
+
parallel (1.23.0)
|
16
|
+
parser (3.2.2.0)
|
26
17
|
ast (~> 2.4.1)
|
27
|
-
|
28
|
-
|
29
|
-
reek (6.0.6)
|
18
|
+
rainbow (3.1.1)
|
19
|
+
reek (6.1.4)
|
30
20
|
kwalify (~> 0.7.0)
|
31
|
-
parser (~> 3.
|
21
|
+
parser (~> 3.2.0)
|
32
22
|
rainbow (>= 2.0, < 4.0)
|
33
|
-
regexp_parser (2.
|
23
|
+
regexp_parser (2.8.0)
|
34
24
|
rexml (3.2.5)
|
35
|
-
rspec (3.
|
36
|
-
rspec-core (~> 3.
|
37
|
-
rspec-expectations (~> 3.
|
38
|
-
rspec-mocks (~> 3.
|
39
|
-
rspec-core (3.
|
40
|
-
rspec-support (~> 3.
|
41
|
-
rspec-expectations (3.
|
25
|
+
rspec (3.12.0)
|
26
|
+
rspec-core (~> 3.12.0)
|
27
|
+
rspec-expectations (~> 3.12.0)
|
28
|
+
rspec-mocks (~> 3.12.0)
|
29
|
+
rspec-core (3.12.2)
|
30
|
+
rspec-support (~> 3.12.0)
|
31
|
+
rspec-expectations (3.12.3)
|
42
32
|
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
-
rspec-support (~> 3.
|
44
|
-
rspec-mocks (3.
|
33
|
+
rspec-support (~> 3.12.0)
|
34
|
+
rspec-mocks (3.12.5)
|
45
35
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
-
rspec-support (~> 3.
|
47
|
-
rspec-support (3.
|
48
|
-
rubocop (1.
|
36
|
+
rspec-support (~> 3.12.0)
|
37
|
+
rspec-support (3.12.0)
|
38
|
+
rubocop (1.50.2)
|
39
|
+
json (~> 2.3)
|
49
40
|
parallel (~> 1.10)
|
50
|
-
parser (>= 3.
|
41
|
+
parser (>= 3.2.0.0)
|
51
42
|
rainbow (>= 2.2.2, < 4.0)
|
52
43
|
regexp_parser (>= 1.8, < 3.0)
|
53
|
-
rexml
|
54
|
-
rubocop-ast (>= 1.
|
44
|
+
rexml (>= 3.2.5, < 4.0)
|
45
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
55
46
|
ruby-progressbar (~> 1.7)
|
56
|
-
unicode-display_width (>=
|
57
|
-
rubocop-ast (1.
|
58
|
-
parser (>= 3.
|
59
|
-
rubocop-
|
47
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
48
|
+
rubocop-ast (1.28.0)
|
49
|
+
parser (>= 3.2.1.0)
|
50
|
+
rubocop-capybara (2.18.0)
|
51
|
+
rubocop (~> 1.41)
|
52
|
+
rubocop-performance (1.17.1)
|
60
53
|
rubocop (>= 1.7.0, < 2.0)
|
61
54
|
rubocop-ast (>= 0.4.0)
|
62
|
-
rubocop-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
rubocop (~> 1.19)
|
68
|
-
ruby-progressbar (1.11.0)
|
69
|
-
semantic (1.6.1)
|
70
|
-
simplecov (0.21.2)
|
55
|
+
rubocop-rspec (2.20.0)
|
56
|
+
rubocop (~> 1.33)
|
57
|
+
rubocop-capybara (~> 2.17)
|
58
|
+
ruby-progressbar (1.13.0)
|
59
|
+
simplecov (0.22.0)
|
71
60
|
docile (~> 1.1)
|
72
61
|
simplecov-html (~> 0.11)
|
73
62
|
simplecov_json_formatter (~> 0.1)
|
74
63
|
simplecov-html (0.12.3)
|
75
|
-
simplecov_json_formatter (0.1.
|
76
|
-
|
77
|
-
concurrent-ruby (~> 1.0)
|
78
|
-
unicode-display_width (2.1.0)
|
79
|
-
zeitwerk (2.5.1)
|
64
|
+
simplecov_json_formatter (0.1.4)
|
65
|
+
unicode-display_width (2.4.2)
|
80
66
|
|
81
67
|
PLATFORMS
|
68
|
+
java
|
82
69
|
ruby
|
83
70
|
|
84
71
|
DEPENDENCIES
|
85
72
|
api_versioner!
|
86
73
|
reek (~> 6.0)
|
87
|
-
rspec (~> 3.
|
74
|
+
rspec (~> 3.12.0)
|
88
75
|
rubocop (~> 1.4)
|
89
76
|
rubocop-performance (~> 1.5, >= 1.5.2)
|
90
|
-
rubocop-rails (~> 2.2)
|
91
77
|
rubocop-rspec (~> 2.0)
|
92
|
-
simplecov (~> 0.
|
78
|
+
simplecov (~> 0.22.0)
|
93
79
|
|
94
80
|
BUNDLED WITH
|
95
|
-
2.
|
81
|
+
2.4.12
|
data/api_versioner.gemspec
CHANGED
@@ -11,11 +11,11 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.summary = 'A simple gem to add semantic versioning support to API applications.'
|
12
12
|
spec.homepage = 'https://github.com/alg/api_versioner'
|
13
13
|
spec.license = 'MIT'
|
14
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
15
15
|
|
16
16
|
spec.metadata['homepage_uri'] = spec.homepage
|
17
17
|
spec.metadata['source_code_uri'] = 'https://github.com/alg/api_versioner'
|
18
|
-
spec.metadata['changelog_uri'] = 'https://github.com/alg/api_versioner/CHANGELOG'
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/alg/api_versioner/CHANGELOG.md'
|
19
19
|
|
20
20
|
# Specify which files should be added to the gem when it is released.
|
21
21
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -25,14 +25,4 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.bindir = 'exe'
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = %w[lib]
|
28
|
-
|
29
|
-
spec.add_dependency 'semantic', '~> 1.6.1'
|
30
|
-
|
31
|
-
spec.add_development_dependency 'reek', '~> 6.0'
|
32
|
-
spec.add_development_dependency 'rspec', '~> 3.10.0'
|
33
|
-
spec.add_development_dependency 'rubocop', '~> 1.4'
|
34
|
-
spec.add_development_dependency 'rubocop-performance', '~> 1.5', '>= 1.5.2'
|
35
|
-
spec.add_development_dependency 'rubocop-rails', '~> 2.2'
|
36
|
-
spec.add_development_dependency 'rubocop-rspec', '~> 2.0'
|
37
|
-
spec.add_development_dependency 'simplecov', '~> 0.21.2'
|
38
28
|
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'semantic'
|
4
|
-
require 'api_versioner/unsupported_version'
|
5
|
-
|
6
3
|
module ApiVersioner
|
4
|
+
autoload :UnsupportedVersion, 'api_versioner/unsupported_version'
|
5
|
+
|
7
6
|
class ClientVersionMiddleware
|
8
7
|
def initialize(app, config = nil)
|
9
8
|
@app = app
|
@@ -32,15 +31,23 @@ module ApiVersioner
|
|
32
31
|
|
33
32
|
def client_version(env)
|
34
33
|
header_name = convert_to_rack_header(@config.client_version_header)
|
35
|
-
|
34
|
+
version_str = presence(env[header_name])
|
35
|
+
return unless version_str
|
36
36
|
|
37
|
-
|
37
|
+
SemanticVersion.new(version_str)
|
38
38
|
rescue ArgumentError
|
39
39
|
nil
|
40
40
|
end
|
41
41
|
|
42
|
+
def presence(str)
|
43
|
+
return unless str
|
44
|
+
|
45
|
+
str = str.strip
|
46
|
+
str.empty? ? nil : str
|
47
|
+
end
|
48
|
+
|
42
49
|
def convert_to_rack_header(header)
|
43
|
-
"HTTP_#{header.
|
50
|
+
"HTTP_#{header.tr('-', '_').upcase}"
|
44
51
|
end
|
45
52
|
end
|
46
53
|
end
|
@@ -1,31 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'semantic'
|
4
|
-
require_relative 'default_policy'
|
5
|
-
require_relative 'default_handler'
|
6
|
-
|
7
3
|
module ApiVersioner
|
4
|
+
autoload :SemanticVersion, 'api_versioner/semantic_version'
|
5
|
+
autoload :DefaultHandler, 'api_versioner/default_handler'
|
6
|
+
autoload :DefaultPolicy, 'api_versioner/default_policy'
|
7
|
+
|
8
|
+
# :reek:InstanceVariableAssumption
|
8
9
|
# :reek:TooManyInstanceVariables
|
9
10
|
class Configuration
|
10
11
|
DEFAULT_SERVER_VERSION_HEADER = 'X-API-Server-Version'
|
11
12
|
DEFAULT_CLIENT_VERSION_HEADER = 'X-API-Client-Version'
|
12
|
-
DEFAULT_VERSION_POLICY = DefaultPolicy.new
|
13
|
-
DEFAULT_UNSUPPORTED_VERSION_HANDLER = DefaultHandler.new
|
14
13
|
|
15
|
-
|
14
|
+
attr_writer :version_policy, :unsupported_version_handler
|
16
15
|
attr_reader :current_version, :server_version_header, :client_version_header
|
17
16
|
|
18
17
|
def initialize
|
19
18
|
@current_version = nil
|
20
19
|
@server_version_header = DEFAULT_SERVER_VERSION_HEADER
|
21
20
|
@client_version_header = DEFAULT_CLIENT_VERSION_HEADER
|
22
|
-
|
23
|
-
|
21
|
+
end
|
22
|
+
|
23
|
+
def version_policy
|
24
|
+
@version_policy = DefaultPolicy.new unless instance_variable_defined?(:@version_policy)
|
25
|
+
@version_policy
|
26
|
+
end
|
27
|
+
|
28
|
+
def unsupported_version_handler
|
29
|
+
@unsupported_version_handler = DefaultHandler.new unless instance_variable_defined?(:@unsupported_version_handler)
|
30
|
+
@unsupported_version_handler
|
24
31
|
end
|
25
32
|
|
26
33
|
def current_version=(version)
|
27
34
|
ver = version.to_s.strip
|
28
|
-
@current_version = ver.empty? ? nil :
|
35
|
+
@current_version = ver.empty? ? nil : SemanticVersion.new(ver)
|
29
36
|
end
|
30
37
|
|
31
38
|
def server_version_header=(name)
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# :nocov:
|
4
|
-
require_relative './client_version_middleware'
|
5
|
-
require_relative './server_version_middleware'
|
6
|
-
|
7
4
|
module ApiVersioner
|
5
|
+
autoload :ServerVersionMiddleware, 'api_versioner/server_version_middleware'
|
6
|
+
autoload :ClientVersionMiddleware, 'api_versioner/client_version_middleware'
|
7
|
+
|
8
8
|
class Railtie < Rails::Railtie
|
9
9
|
initializer 'versioner.configure_rails_initialization' do |app|
|
10
10
|
app.middleware.use ServerVersionMiddleware
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module ApiVersioner
|
6
|
+
class SemanticVersion
|
7
|
+
extend Forwardable
|
8
|
+
include Comparable
|
9
|
+
|
10
|
+
# https://semver.org
|
11
|
+
REGEXP = /\A(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?\z/.freeze # rubocop:disable Layout/LineLength
|
12
|
+
|
13
|
+
def initialize(version)
|
14
|
+
match = REGEXP.match(version)
|
15
|
+
raise ArgumentError, "#{version.inspect} is not a valid SemVer Version (http://semver.org)" unless match
|
16
|
+
|
17
|
+
@version = Version.new(match)
|
18
|
+
end
|
19
|
+
|
20
|
+
def_delegators :@version, :to_s, :major, :minor, :patch, :pre, :build, :prerelease_identifiers
|
21
|
+
|
22
|
+
def <=>(other)
|
23
|
+
other = SemanticVersion.new(other) if other.is_a?(String)
|
24
|
+
Compare.new(self, other).()
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# :reek:TooManyInstanceVariables
|
29
|
+
class Version
|
30
|
+
NUMERIC = /\A0|[1-9]\d*\z/.freeze
|
31
|
+
|
32
|
+
attr_reader :version, :major, :minor, :patch, :pre, :build, :prerelease_identifiers
|
33
|
+
|
34
|
+
def initialize(regexp_match)
|
35
|
+
@version = regexp_match.string
|
36
|
+
@major = regexp_match[:major].to_i
|
37
|
+
@minor = regexp_match[:minor].to_i
|
38
|
+
@patch = regexp_match[:patch].to_i
|
39
|
+
@pre = regexp_match[:prerelease]
|
40
|
+
@build = regexp_match[:buildmetadata]
|
41
|
+
@prerelease_identifiers = parse_prerelease_identifiers(@pre)
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
version
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def parse_prerelease_identifiers(pre)
|
51
|
+
return nil unless pre
|
52
|
+
|
53
|
+
pre.split('.').map! { |id| NUMERIC.match?(id) ? id.to_i : id }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class Compare
|
58
|
+
def initialize(version1, version2)
|
59
|
+
@version1 = version1
|
60
|
+
@version2 = version2
|
61
|
+
end
|
62
|
+
|
63
|
+
# :reek:TooManyStatements
|
64
|
+
# rubocop:disable Metrics/AbcSize
|
65
|
+
def call
|
66
|
+
by_major = version1.major <=> version2.major
|
67
|
+
return by_major unless by_major.zero?
|
68
|
+
|
69
|
+
by_minor = version1.minor <=> version2.minor
|
70
|
+
return by_minor unless by_minor.zero?
|
71
|
+
|
72
|
+
by_patch = version1.patch <=> version2.patch
|
73
|
+
return by_patch unless by_patch.zero?
|
74
|
+
|
75
|
+
compare_prereleases(version1.prerelease_identifiers, version2.prerelease_identifiers)
|
76
|
+
end
|
77
|
+
# rubocop:enable Metrics/AbcSize
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
attr_reader :version1, :version2
|
82
|
+
|
83
|
+
# :reek:TooManyStatements
|
84
|
+
# :reek:FeatureEnvy
|
85
|
+
def compare_prereleases(ids1, ids2)
|
86
|
+
# A pre-release version has lower precedence than a normal version
|
87
|
+
return 0 if !ids1 && !ids2
|
88
|
+
return 1 unless ids1
|
89
|
+
return -1 unless ids2
|
90
|
+
|
91
|
+
# Compare pre-release identifiers one-by-one
|
92
|
+
each_prerelease_pair(ids1, ids2) do |id1, id2|
|
93
|
+
by_prerelease = compare_prerelease(id1, id2)
|
94
|
+
return by_prerelease unless by_prerelease.zero?
|
95
|
+
end
|
96
|
+
|
97
|
+
0
|
98
|
+
end
|
99
|
+
|
100
|
+
# :reek:TooManyStatements
|
101
|
+
def compare_prerelease(id1, id2)
|
102
|
+
# A larger set of pre-release fields has a higher precedence than a smaller set
|
103
|
+
return -1 unless id1
|
104
|
+
return 1 unless id2
|
105
|
+
|
106
|
+
id1_is_numeric = id1.is_a?(Integer)
|
107
|
+
id2_is_numeric = id2.is_a?(Integer)
|
108
|
+
|
109
|
+
# Numeric identifiers always have lower precedence than non-numeric identifiers.
|
110
|
+
return -1 if id1_is_numeric && !id2_is_numeric
|
111
|
+
return 1 if !id1_is_numeric && id2_is_numeric
|
112
|
+
|
113
|
+
id1 <=> id2
|
114
|
+
end
|
115
|
+
|
116
|
+
# :reek:TooManyStatements
|
117
|
+
def each_prerelease_pair(ids1, ids2)
|
118
|
+
index = 0
|
119
|
+
|
120
|
+
loop do
|
121
|
+
id1 = ids1[index]
|
122
|
+
id2 = ids2[index]
|
123
|
+
break if !id1 && !id2
|
124
|
+
|
125
|
+
yield(id1, id2)
|
126
|
+
index += 1
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -8,11 +8,9 @@ module ApiVersioner
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(env)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
[status, headers, response]
|
11
|
+
response = @app.(env) # status, headers, bodies
|
12
|
+
add_version_header(response[1])
|
13
|
+
response
|
16
14
|
end
|
17
15
|
|
18
16
|
private
|
@@ -20,7 +18,7 @@ module ApiVersioner
|
|
20
18
|
def add_version_header(headers)
|
21
19
|
return unless adding_versions?
|
22
20
|
|
23
|
-
headers[@config.server_version_header] = @config.current_version
|
21
|
+
headers[@config.server_version_header] = @config.current_version
|
24
22
|
end
|
25
23
|
|
26
24
|
def adding_versions?
|
data/lib/api_versioner.rb
CHANGED
metadata
CHANGED
@@ -1,134 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_versioner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksey Gureiev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
name: semantic
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.6.1
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 1.6.1
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: reek
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '6.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '6.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 3.10.0
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 3.10.0
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '1.4'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '1.4'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubocop-performance
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.5'
|
76
|
-
- - ">="
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version: 1.5.2
|
79
|
-
type: :development
|
80
|
-
prerelease: false
|
81
|
-
version_requirements: !ruby/object:Gem::Requirement
|
82
|
-
requirements:
|
83
|
-
- - "~>"
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: '1.5'
|
86
|
-
- - ">="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: 1.5.2
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: rubocop-rails
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: '2.2'
|
96
|
-
type: :development
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: '2.2'
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: rubocop-rspec
|
105
|
-
requirement: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - "~>"
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '2.0'
|
110
|
-
type: :development
|
111
|
-
prerelease: false
|
112
|
-
version_requirements: !ruby/object:Gem::Requirement
|
113
|
-
requirements:
|
114
|
-
- - "~>"
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: '2.0'
|
117
|
-
- !ruby/object:Gem::Dependency
|
118
|
-
name: simplecov
|
119
|
-
requirement: !ruby/object:Gem::Requirement
|
120
|
-
requirements:
|
121
|
-
- - "~>"
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version: 0.21.2
|
124
|
-
type: :development
|
125
|
-
prerelease: false
|
126
|
-
version_requirements: !ruby/object:Gem::Requirement
|
127
|
-
requirements:
|
128
|
-
- - "~>"
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
version: 0.21.2
|
131
|
-
description:
|
11
|
+
date: 2023-04-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
132
14
|
email:
|
133
15
|
- agureiev@shakuro.com
|
134
16
|
executables: []
|
@@ -137,12 +19,13 @@ extra_rdoc_files: []
|
|
137
19
|
files:
|
138
20
|
- ".devcontainer/Dockerfile"
|
139
21
|
- ".devcontainer/devcontainer.json"
|
22
|
+
- ".github/workflows/main.yml"
|
140
23
|
- ".gitignore"
|
141
24
|
- ".reek.yml"
|
142
25
|
- ".rspec"
|
143
26
|
- ".rubocop.yml"
|
144
27
|
- ".travis.yml"
|
145
|
-
- CHANGELOG
|
28
|
+
- CHANGELOG.md
|
146
29
|
- CODE_OF_CONDUCT.md
|
147
30
|
- Gemfile
|
148
31
|
- Gemfile.lock
|
@@ -158,6 +41,7 @@ files:
|
|
158
41
|
- lib/api_versioner/default_handler.rb
|
159
42
|
- lib/api_versioner/default_policy.rb
|
160
43
|
- lib/api_versioner/railtie.rb
|
44
|
+
- lib/api_versioner/semantic_version.rb
|
161
45
|
- lib/api_versioner/server_version_middleware.rb
|
162
46
|
- lib/api_versioner/unsupported_version.rb
|
163
47
|
- lib/api_versioner/version.rb
|
@@ -167,8 +51,8 @@ licenses:
|
|
167
51
|
metadata:
|
168
52
|
homepage_uri: https://github.com/alg/api_versioner
|
169
53
|
source_code_uri: https://github.com/alg/api_versioner
|
170
|
-
changelog_uri: https://github.com/alg/api_versioner/CHANGELOG
|
171
|
-
post_install_message:
|
54
|
+
changelog_uri: https://github.com/alg/api_versioner/CHANGELOG.md
|
55
|
+
post_install_message:
|
172
56
|
rdoc_options: []
|
173
57
|
require_paths:
|
174
58
|
- lib
|
@@ -176,7 +60,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
176
60
|
requirements:
|
177
61
|
- - ">="
|
178
62
|
- !ruby/object:Gem::Version
|
179
|
-
version: 2.
|
63
|
+
version: 2.6.0
|
180
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
65
|
requirements:
|
182
66
|
- - ">="
|
@@ -184,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
68
|
version: '0'
|
185
69
|
requirements: []
|
186
70
|
rubygems_version: 3.1.6
|
187
|
-
signing_key:
|
71
|
+
signing_key:
|
188
72
|
specification_version: 4
|
189
73
|
summary: A simple gem to add semantic versioning support to API applications.
|
190
74
|
test_files: []
|
data/CHANGELOG
DELETED
File without changes
|