From b860bdfd27352dd17b51471c13a10872a675979f Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Tue, 22 Dec 2020 14:27:12 -0500 Subject: [PATCH] Fix lint issues Add getters for more specialized negotiators --- .github/workflows/ci.yml | 4 ++++ .github/workflows/deployment.yml | 4 +++- README.md | 2 +- src/abstract_negotiator.cr | 4 ++-- src/athena-negotiation.cr | 10 ++++++++++ src/base_accept.cr | 2 +- src/negotiator.cr | 3 +++ 7 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2296d37..34c5a4b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,8 @@ jobs: image: crystallang/crystal:latest-alpine steps: - uses: actions/checkout@v2 + - name: Install Dependencies + run: shards install - name: Specs run: crystal spec --order random --error-on-warnings test_nightly: @@ -40,5 +42,7 @@ jobs: image: crystallang/crystal:nightly-alpine steps: - uses: actions/checkout@v2 + - name: Install Dependencies + run: shards install - name: Specs run: crystal spec --order random --error-on-warnings diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index d63dbbc..095862e 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -14,8 +14,10 @@ jobs: - name: Install Build Dependencies run: apk add --update rsync - uses: actions/checkout@v2 + - name: Install Dependencies + run: shards install - name: Build - run: crystal docs + run: crystal docs lib/athena-spec/src/athena-spec.cr src/athena-negotiation.cr - name: Deploy uses: JamesIves/github-pages-deploy-action@3.7.1 with: diff --git a/README.md b/README.md index 584657d..eb8264a 100644 --- a/README.md +++ b/README.md @@ -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) [![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 diff --git a/src/abstract_negotiator.cr b/src/abstract_negotiator.cr index 66d4296..a7e9dbd 100644 --- a/src/abstract_negotiator.cr +++ b/src/abstract_negotiator.cr @@ -26,8 +26,8 @@ abstract class Athena::Negotiation::AbstractNegotiator matches = self.find_matches accepted_headers, accepted_priorties - specific_matches = matches.reduce({} of Int32 => ANG::AcceptMatch) do |matches, match| - ANG::AcceptMatch.reduce matches, match + specific_matches = matches.reduce({} of Int32 => ANG::AcceptMatch) do |acc, match| + ANG::AcceptMatch.reduce acc, match end.values specific_matches.sort! diff --git a/src/athena-negotiation.cr b/src/athena-negotiation.cr index 3b511f2..b57f7a5 100644 --- a/src/athena-negotiation.cr +++ b/src/athena-negotiation.cr @@ -14,5 +14,15 @@ require "./exceptions/*" alias ANG = Athena::Negotiation module Athena::Negotiation + # Returns an `ANG::Negotiation` singleton instance. 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 diff --git a/src/base_accept.cr b/src/base_accept.cr index 29896da..e4f703b 100644 --- a/src/base_accept.cr +++ b/src/base_accept.cr @@ -29,7 +29,7 @@ abstract struct Athena::Negotiation::BaseAccept unless @parameters.empty? io << "; " # 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 diff --git a/src/negotiator.cr b/src/negotiator.cr index 07ee439..28c0e26 100644 --- a/src/negotiator.cr +++ b/src/negotiator.cr @@ -1,6 +1,9 @@ require "./abstract_negotiator" 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? accept_base = accept.base_part priority_base = priority.base_part