ArchTest.ModuleSet (ArchTest v0.2.0)

Copy Markdown View Source

Represents a lazy selection of modules for use in architecture rules.

A ModuleSet is created with one or more include patterns and optional exclude patterns. Actual module resolution is deferred until resolve/2 is called with a dependency graph.

Building a ModuleSet

import ArchTest

modules_matching("MyApp.Orders.*")
modules_matching("MyApp.Orders.**")
modules_in("MyApp.Orders")
all_modules()

Composing ModuleSets

modules_matching("**.*Controller")
|> excluding("MyApp.Web.ErrorController")

modules_matching("**.*Service")
|> union(modules_matching("**.*View"))

modules_matching("MyApp.**")
|> intersection(modules_matching("**.*Schema"))

Summary

Functions

Creates a ModuleSet that matches all modules.

Adds exclude patterns to a ModuleSet.

Creates a ModuleSet for all direct children of namespace.

Returns a new ModuleSet matching modules in both sets (intersection / AND).

Creates a ModuleSet matching the given glob pattern.

Resolves the ModuleSet against the given dependency graph.

Creates a ModuleSet using a custom filter function.

Returns a new ModuleSet matching modules in either set (union / OR).

Types

t()

@type t() :: %ArchTest.ModuleSet{
  app: atom() | nil,
  custom_filter: (module() -> boolean()) | nil,
  exclude_patterns: [String.t()],
  include_patterns: [String.t()]
}

Functions

all()

@spec all() :: t()

Creates a ModuleSet that matches all modules.

excluding(ms, pattern)

@spec excluding(t(), String.t() | [String.t()]) :: t()

Adds exclude patterns to a ModuleSet.

in_namespace(namespace)

@spec in_namespace(String.t()) :: t()

Creates a ModuleSet for all direct children of namespace.

Equivalent to modules_matching("Namespace.*").

intersection(a, b)

@spec intersection(t(), t()) :: t()

Returns a new ModuleSet matching modules in both sets (intersection / AND).

A module is included only if it matches both set a AND set b.

new(pattern)

@spec new(String.t() | [String.t()]) :: t()

Creates a ModuleSet matching the given glob pattern.

Examples

iex> import ArchTest
iex> ms = modules_matching("MyApp.Orders.*")
iex> %ArchTest.ModuleSet{include_patterns: ["MyApp.Orders.*"]} = ms

resolve(ms, graph)

@spec resolve(t(), ArchTest.Collector.graph()) :: [module()]

Resolves the ModuleSet against the given dependency graph.

Returns the list of actual module atoms that match the set's patterns.

satisfying(filter_fn)

@spec satisfying((module() -> boolean())) :: t()

Creates a ModuleSet using a custom filter function.

The function receives a module atom and returns true to include it.

Example

modules_satisfying(fn mod ->
  function_exported?(mod, :__schema__, 1)
end)

union(a, b)

@spec union(t(), t()) :: t()

Returns a new ModuleSet matching modules in either set (union / OR).

A module is included if it matches set a OR set b (with each set's own include/exclude/custom_filter applied independently).