Fix lint issues

Add getters for more specialized negotiators
This commit is contained in:
George Dietrich 2020-12-22 14:27:12 -05:00
parent 3850074f02
commit b860bdfd27
7 changed files with 24 additions and 5 deletions

View file

@ -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

View file

@ -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:

View file

@ -3,7 +3,7 @@
[![CI](https://github.com/athena-framework/negotiation/workflows/CI/badge.svg)](https://github.com/athena-framework/negotiation/actions?query=workflow%3ACI) [![CI](https://github.com/athena-framework/negotiation/workflows/CI/badge.svg)](https://github.com/athena-framework/negotiation/actions?query=workflow%3ACI)
[![Latest release](https://img.shields.io/github/release/athena-framework/negotiation.svg)](https://github.com/athena-framework/negotiation/releases) [![Latest release](https://img.shields.io/github/release/athena-framework/negotiation.svg)](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

View file

@ -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!

View file

@ -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

View file

@ -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

View file

@ -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