class Rack::ServiceApiVersioning::MatchHeaderAgainstApiVersions
Matches content of HTTP Accept header against presently-available API Versions. Returns either a symbolic value (e.g., `:v2`) on success or `nil` on failure.
Attributes
accept_header[R]
api_versions[R]
Public Class Methods
call(accept_header:, api_versions:)
click to toggle source
# File lib/rack/service_api_versioning/match_header_against_api_versions.rb, line 14 def self.call(accept_header:, api_versions:) new(accept_header, api_versions).call end
new(accept_header, api_versions)
click to toggle source
# File lib/rack/service_api_versioning/match_header_against_api_versions.rb, line 24 def initialize(accept_header, api_versions) @accept_header = accept_header @api_versions = api_versions self end
Public Instance Methods
call()
click to toggle source
# File lib/rack/service_api_versioning/match_header_against_api_versions.rb, line 18 def call best_match end
Private Instance Methods
all_matches()
click to toggle source
# File lib/rack/service_api_versioning/match_header_against_api_versions.rb, line 34 def all_matches api_versions.select { |_, version| best_type?(version) } end
all_types()
click to toggle source
# File lib/rack/service_api_versioning/match_header_against_api_versions.rb, line 38 def all_types api_versions.values.map { |version| version[:content_type] } end
best_match()
click to toggle source
# File lib/rack/service_api_versioning/match_header_against_api_versions.rb, line 42 def best_match all_matches.keys.first end
best_type()
click to toggle source
# File lib/rack/service_api_versioning/match_header_against_api_versions.rb, line 46 def best_type Rack::Utils.best_q_match(accept_header, all_types) end
best_type?(version)
click to toggle source
# File lib/rack/service_api_versioning/match_header_against_api_versions.rb, line 50 def best_type?(version) version[:content_type] == best_type end