Module: ArchUnit::Common::FluentApi::Checkable

Overview

The shared execution contract implemented by every terminal rule.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rationale ⇒ String? (readonly)

Optional normalized explanation, kept separate from violation values.

Returns:

  • (String, nil)


16
17
18
# File 'lib/archunit/common/fluentapi/checkable.rb', line 16

def rationale
  @rationale
end

Instance Method Details

#because(reason) ⇒ Checkable

Explains why this completed rule exists, without changing the original. Append this after all selectors and modifiers.

Parameters:

  • reason (String) —

    a non-blank human-readable explanation

Returns:

  • (Checkable) —

    a distinct frozen rule of the same type



22
23
24
25
26
27
28
29
30
# File 'lib/archunit/common/fluentapi/checkable.rb', line 22

def because(reason)
  unless reason.is_a?(String) && !reason.strip.empty?
    raise ArgumentError, 'reason must be a non-empty String'
  end

  copy = dup
  copy.instance_variable_set(:@rationale, reason.strip.freeze)
  copy.freeze
end

#check(options = nil) ⇒ Array<ArchUnit::Violation>

Executes the rule and returns every architecture disagreement as structured data.

Parameters:

Returns:



35
36
37
38
39
40
41
42
43
# File 'lib/archunit/common/fluentapi/checkable.rb', line 35

def check(options = nil)
  resolved_options = CheckOptions.resolve(options)
  logger = Logging::CheckLogger.new(resolved_options.logging)
  check_name = self.class.name || self.class.to_s
  logger.start_check(check_name)
  execute_check(resolved_options, logger, check_name)
ensure
  logger&.close
end