mirror of
https://gitea.invidious.io/iv-org/shard-athena-negotiation.git
synced 2024-08-15 00:53:23 +00:00
Fix lint issues
Add getters for more specialized negotiators
This commit is contained in:
parent
3850074f02
commit
b860bdfd27
7 changed files with 24 additions and 5 deletions
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
@ -32,6 +32,8 @@ jobs:
|
||||||
image: crystallang/crystal:latest-alpine
|
image: crystallang/crystal:latest-alpine
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: shards install
|
||||||
- name: Specs
|
- name: Specs
|
||||||
run: crystal spec --order random --error-on-warnings
|
run: crystal spec --order random --error-on-warnings
|
||||||
test_nightly:
|
test_nightly:
|
||||||
|
@ -40,5 +42,7 @@ jobs:
|
||||||
image: crystallang/crystal:nightly-alpine
|
image: crystallang/crystal:nightly-alpine
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: shards install
|
||||||
- name: Specs
|
- name: Specs
|
||||||
run: crystal spec --order random --error-on-warnings
|
run: crystal spec --order random --error-on-warnings
|
||||||
|
|
4
.github/workflows/deployment.yml
vendored
4
.github/workflows/deployment.yml
vendored
|
@ -14,8 +14,10 @@ jobs:
|
||||||
- name: Install Build Dependencies
|
- name: Install Build Dependencies
|
||||||
run: apk add --update rsync
|
run: apk add --update rsync
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: shards install
|
||||||
- name: Build
|
- name: Build
|
||||||
run: crystal docs
|
run: crystal docs lib/athena-spec/src/athena-spec.cr src/athena-negotiation.cr
|
||||||
- name: Deploy
|
- name: Deploy
|
||||||
uses: JamesIves/github-pages-deploy-action@3.7.1
|
uses: JamesIves/github-pages-deploy-action@3.7.1
|
||||||
with:
|
with:
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
[](https://github.com/athena-framework/negotiation/actions?query=workflow%3ACI)
|
[](https://github.com/athena-framework/negotiation/actions?query=workflow%3ACI)
|
||||||
[](https://github.com/athena-framework/negotiation/releases)
|
[](https://github.com/athena-framework/negotiation/releases)
|
||||||
|
|
||||||
Framework agnostic content negotiation library.
|
Framework agnostic [content negotiation](https://tools.ietf.org/html/rfc7231#section-5.3) library based on [willdurand/Negotiation](https://github.com/willdurand/Negotiation).
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,8 @@ abstract class Athena::Negotiation::AbstractNegotiator
|
||||||
|
|
||||||
matches = self.find_matches accepted_headers, accepted_priorties
|
matches = self.find_matches accepted_headers, accepted_priorties
|
||||||
|
|
||||||
specific_matches = matches.reduce({} of Int32 => ANG::AcceptMatch) do |matches, match|
|
specific_matches = matches.reduce({} of Int32 => ANG::AcceptMatch) do |acc, match|
|
||||||
ANG::AcceptMatch.reduce matches, match
|
ANG::AcceptMatch.reduce acc, match
|
||||||
end.values
|
end.values
|
||||||
|
|
||||||
specific_matches.sort!
|
specific_matches.sort!
|
||||||
|
|
|
@ -14,5 +14,15 @@ require "./exceptions/*"
|
||||||
alias ANG = Athena::Negotiation
|
alias ANG = Athena::Negotiation
|
||||||
|
|
||||||
module Athena::Negotiation
|
module Athena::Negotiation
|
||||||
|
# Returns an `ANG::Negotiation` singleton instance.
|
||||||
class_getter(negotiator) { ANG::Negotiator.new }
|
class_getter(negotiator) { ANG::Negotiator.new }
|
||||||
|
|
||||||
|
# Returns an `ANG::CharsetNegotiator` singleton instance.
|
||||||
|
class_getter(charset_negotiator) { ANG::CharsetNegotiator.new }
|
||||||
|
|
||||||
|
# Returns an `ANG::EncodingNegotiator` singleton instance.
|
||||||
|
class_getter(encoding_negotiator) { ANG::EncodingNegotiator.new }
|
||||||
|
|
||||||
|
# Returns an `ANG::LanguageNegotiator` singleton instance.
|
||||||
|
class_getter(language_negotiator) { ANG::LanguageNegotiator.new }
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,7 +29,7 @@ abstract struct Athena::Negotiation::BaseAccept
|
||||||
unless @parameters.empty?
|
unless @parameters.empty?
|
||||||
io << "; "
|
io << "; "
|
||||||
# TODO: Do we care the parameters aren't sorted?
|
# TODO: Do we care the parameters aren't sorted?
|
||||||
parameters.join(io, "; ") { |(k, v), io| io << "#{k}=#{v}" }
|
parameters.join(io, "; ") { |(k, v), join_io| join_io << "#{k}=#{v}" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
require "./abstract_negotiator"
|
require "./abstract_negotiator"
|
||||||
|
|
||||||
class Athena::Negotiation::Negotiator < Athena::Negotiation::AbstractNegotiator
|
class Athena::Negotiation::Negotiator < Athena::Negotiation::AbstractNegotiator
|
||||||
|
# TODO: Make this method less complex.
|
||||||
|
#
|
||||||
|
# ameba:disable Metrics/CyclomaticComplexity
|
||||||
protected def match(accept : ANG::Accept, priority : ANG::Accept, index : Int32) : ANG::AcceptMatch?
|
protected def match(accept : ANG::Accept, priority : ANG::Accept, index : Int32) : ANG::AcceptMatch?
|
||||||
accept_base = accept.base_part
|
accept_base = accept.base_part
|
||||||
priority_base = priority.base_part
|
priority_base = priority.base_part
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue