Commit baadb280 authored by Sam Wiskow's avatar Sam Wiskow
Browse files

style: fix rubocop offenses

- Replace em-dash (U+2014) in comments with ASCII hyphen
- Expand single-line hook blocks to multi-line
- Rename short method params (v -> val, r/l -> removed)
- Remove unused `id` argument from evaluator helper
- Rewrite multi-line lambda literals with do/end for alignment

Co-Authored-By: default avatarClaude Sonnet 4.6 <noreply@anthropic.com>
parent 963e542a
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ module Labkit
        @config ||= Configuration.new
      end

      # Convenience wrapper  creates a throw-away Limiter.
      # Convenience wrapper - creates a throw-away Limiter.
      # Prefer Limiter for call sites that can cache the object.
      #
      # @param name [String] call site name
+2 −3
Original line number Diff line number Diff line
@@ -75,8 +75,8 @@ module Labkit
        value.to_s
      end

      def resolve_value(v)
        v.respond_to?(:call) ? v.call : v
      def resolve_value(val)
        val.respond_to?(:call) ? val.call : val
      end

      def encode_char_value(value)
@@ -129,7 +129,6 @@ module Labkit
          identifier: identifier&.to_h
        )
      end

    end
  end
end
+1 −3
Original line number Diff line number Diff line
@@ -45,9 +45,7 @@ module Labkit
      def validate_name!(name, logger)
        return name if NAME_PATTERN.match?(name)

        if dev_or_test?
          raise ArgumentError, "Invalid name: #{name.inspect}. Must match /\\A[a-z0-9_]+\\z/"
        end
        raise ArgumentError, "Invalid name: #{name.inspect}. Must match /\\A[a-z0-9_]+\\z/" if dev_or_test?

        sanitized = name.gsub(/[^a-z0-9_]/, "_")
        logger.warn(message: "rate_limit_invalid_name", name: name, sanitized: sanitized)
+17 −9
Original line number Diff line number Diff line
@@ -3,19 +3,27 @@
module Labkit
  module RateLimit
    # Result is the return value of Limiter#check.
    # matched?  true if a rule's match conditions were satisfied
    # exceeded?  true if the matched rule's counter exceeded its limit
    # action     :block or :log (nil when matched? is false)
    # rule       the matched Rule object (nil when matched? is false)
    # error?     true if Redis was unavailable; result fails open (exceeded? is false)
    # matched?  - true if a rule's match conditions were satisfied
    # exceeded? - true if the matched rule's counter exceeded its limit
    # action    - :block or :log (nil when matched? is false)
    # rule      - the matched Rule object (nil when matched? is false)
    # error?    - true if Redis was unavailable; result fails open (exceeded? is false)
    Result = Data.define(:matched, :exceeded, :action, :rule, :error) do
      def initialize(matched:, exceeded: false, action: nil, rule: nil, error: false)
        super(matched: matched, exceeded: exceeded, action: action, rule: rule, error: error)
        super
      end

      def matched? = matched
      def exceeded? = exceeded
      def error? = error
      def matched?
        matched
      end

      def exceeded?
        exceeded
      end

      def error?
        error
      end
    end
  end
end
+6 −6
Original line number Diff line number Diff line
@@ -3,13 +3,13 @@
module Labkit
  module RateLimit
    # Rule is a value object describing a single rate limit rule.
    # name             stable identifier used in Redis keys and log entries
    # match            hash of identifier key/value pairs that must all match for
    # name            - stable identifier used in Redis keys and log entries
    # match           - hash of identifier key/value pairs that must all match for
    #                   the rule to apply; empty hash matches any identifier
    # limit            request threshold; may be a callable (resolved per check)
    # period           window in seconds; may be a callable (resolved per check)
    # action           :block (enforce) or :log (count and log, but do not block)
    # characteristics  identifier keys used to build the compound Redis counter key
    # limit           - request threshold; may be a callable (resolved per check)
    # period          - window in seconds; may be a callable (resolved per check)
    # action          - :block (enforce) or :log (count and log, but do not block)
    # characteristics - identifier keys used to build the compound Redis counter key
    Rule = Data.define(:name, :match, :limit, :period, :action, :characteristics) do
      def initialize(name:, limit:, period:, characteristics:, match: {}, action: :block)
        super(
Loading