Class: Trane::RouteValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/trane/route_validator.rb

Overview

Cross-checks drawn routes against the operation registry. Two independent checks, each with its own failure message:

1. Every route declaring `_trane_operation` must reference a registered
 operation (catches typos in `contract: { operation: :x }`).
2. Every such route must map to exactly one HTTP verb (a Trane operation
 is one verb + one path). Rails collapses `via: [:patch, :put]` into a
 single route whose #verb is "PATCH|PUT"; a `match` with no verb (or
 `via: :all`) yields a blank verb matching any method. Both are rejected.

Pure (routes, registry) function — no Rails::Application coupling — so it can be exercised with fake route doubles in unit specs and with a real route set from the Engine or the trane:check rake task.

Class Method Summary collapse

Class Method Details

.validate!(routes, registry) ⇒ Object

Parameters:

  • routes (Enumerable)

    route objects responding to #verb, #defaults, #path

  • registry (Module, Trane::Registry::Instance)

    responds to #operations

Raises:



22
23
24
25
# File 'lib/trane/route_validator.rb', line 22

def self.validate!(routes, registry)
  validate_operations_registered!(routes, registry)
  validate_single_verb!(routes)
end