module ArchSpec
ArchSpec turns your application’s architecture into executable checks.
You describe components, dependencies, and boundaries in an Archspec.rb file written in the ArchSpec::DSL, then run archspec check to verify every change. ArchSpec reads Ruby source with Prism and never boots the app.
The DSL is the public API. An Archspec.rb file is evaluated directly:
architecture :rails component :services, in: "app/services/**/*.rb" services.cannot_call :render, :redirect_to, receiver: :none
See ArchSpec::DSL::Context for the top-level DSL and ArchSpec::DSL::ComponentProxy for per-component rules. See ArchSpec::Architectures for the bundled architecture presets.
You can also build a definition in plain Ruby with ArchSpec.define.
Constants
- VERSION
Attributes
The definition produced by the most recent ArchSpec.define call, or by evaluating an Archspec.rb file. The CLI reads this after loading config.
Public Class Methods
Source
# File lib/archspec.rb, line 68 def define(name = nil, &block) definition = Definition.new(name) definition.extend(DSL::Context) definition.instance_eval(&block) if block self.last_definition = definition end
Builds an architecture definition from a block of DSL calls.
ArchSpec.define do component :models, in: "app/models/**/*.rb" component :controllers, in: "app/controllers/**/*.rb" models.cannot_use :controllers end
An Archspec.rb file does not need this wrapper. Its top level is already the DSL, so bare component and architecture calls work directly. Use define when constructing a definition from Ruby, such as in a test.
Returns the ArchSpec::Definition, which is also stored as last_definition.