Class: DevDoc::Test::Lints::ExternalIoBoundaryChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/dev_doc/test/lints/external_io_boundary.rb

Overview

Framework-agnostic check: scans Ruby sources under app/ (excluding app/services/) for HTTP-client tokens and returns offender descriptions for every hit.

Wrapped by the Minitest module ExternalIoBoundary below — see that module for the rationale.

Constant Summary collapse

DEFAULT_HTTP_CLIENT_TOKENS =

The generic Ruby HTTP-client surface. Provider SDKs (Stripe, AWS, etc.) are project vocabulary and belong in the per-project token override on the ExternalIoBoundary module, not here.

%w[
  Net::HTTP Faraday HTTParty RestClient OpenURI URI.open Typhoeus Excon Curl
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(project_root, tokens: DEFAULT_HTTP_CLIENT_TOKENS, allowed_paths: []) ⇒ ExternalIoBoundaryChecker

Returns a new instance of ExternalIoBoundaryChecker.



20
21
22
23
24
# File 'lib/dev_doc/test/lints/external_io_boundary.rb', line 20

def initialize(project_root, tokens: DEFAULT_HTTP_CLIENT_TOKENS, allowed_paths: [])
  @project_root = Pathname(project_root)
  @tokens = tokens
  @allowed_paths = allowed_paths
end

Instance Method Details

#offendersObject

Returns an Array of offender descriptions (" app/models/foo.rb:12: Net::HTTP"), or [] when the boundary holds. Token matching is boundary-aware, so Net::HTTP does not fire on Net::HTTPSuccess and Curl does not fire on Curly.



30
31
32
# File 'lib/dev_doc/test/lints/external_io_boundary.rb', line 30

def offenders
  ruby_files.flat_map { |path| file_offenders(path) }
end