Module: ArchSpec

Defined in:
lib/archspec.rb,
lib/archspec/cli.rb,
lib/archspec/dsl.rb,
lib/archspec/todo.rb,
lib/archspec/error.rb,
lib/archspec/model.rb,
lib/archspec/version.rb,
lib/archspec/analyzer.rb,
lib/archspec/evaluator.rb,
lib/archspec/definition.rb,
lib/archspec/diagnostic.rb,
lib/archspec/architectures.rb,
lib/archspec/rubydex_index.rb,
lib/archspec/component_spec.rb,
lib/archspec/rules/reasoned.rb,
lib/archspec/formatters/json.rb,
lib/archspec/formatters/text.rb,
lib/archspec/source_location.rb,
lib/archspec/formatters/style.rb,
lib/archspec/rules/cycle_rule.rb,
lib/archspec/rules/naming_rules.rb,
lib/archspec/rules/privacy_rule.rb,
lib/archspec/rules/concern_rules.rb,
lib/archspec/rules/protocol_rules.rb,
lib/archspec/rules/component_rules.rb,
lib/archspec/formatters/explanation.rb,
lib/archspec/rules/dependency_rules.rb

Overview

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 indexes Ruby source with Rubydex, uses Prism for a handful of syntax-specific facts, 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.

Defined Under Namespace

Modules: Analyzer, Architectures, CLI, DSL, Evaluator, Formatters, Rules Classes: AnalysisDiagnostic, Component, ComponentSpec, ConstantNode, Definition, Diagnostic, Edge, Error, Graph, MethodDefinition, MethodSignature, ParseError, RubydexIndex, SourceFile, SourceLocation, Suppression, Todo

Constant Summary collapse

VERSION =
'1.1.0'

Class Method Summary collapse

Class Method Details

.define(name = nil, &block) ⇒ Object

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 is not written with 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.



65
66
67
68
69
70
# File 'lib/archspec.rb', line 65

def define(name = nil, &block)
  definition = Definition.new(name)
  definition.extend(DSL::Context)
  definition.instance_eval(&block) if block
  definition
end