Class: ArchUnit::Common::FluentApi::CheckOptions

Inherits:
Data
  • Object
show all
Defined in:
lib/archunit/common/fluentapi/check_options.rb

Overview

Immutable options shared by every terminal rule check.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(allow_empty_tests: false, logging: nil, clear_cache: false, load_paths: [], dependency_analysis: :imports) ⇒ CheckOptions

Returns a new instance of CheckOptions.

Parameters:

  • allow_empty_tests (Boolean) (defaults to: false) —

    permit a selector that finds no subjects

  • logging (LoggingOptions, nil) (defaults to: nil) —

    per-check logging configuration

  • clear_cache (Boolean) (defaults to: false) —

    rebuild the dependency graph for this check

  • load_paths (Array<String, Pathname>) (defaults to: []) —

    additional project-contained source roots

  • dependency_analysis (Symbol) (defaults to: :imports) —

    :imports or opt-in :imports_and_constants



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/archunit/common/fluentapi/check_options.rb', line 27

def initialize(
  allow_empty_tests: false, logging: nil, clear_cache: false, load_paths: [],
  dependency_analysis: :imports
)
  validate_boolean(allow_empty_tests, :allow_empty_tests)
  validate_logging(logging)
  validate_boolean(clear_cache, :clear_cache)
  load_paths = immutable_load_paths(load_paths)
  unless %i[imports imports_and_constants].include?(dependency_analysis)
    raise ArgumentError, 'dependency_analysis must be :imports or :imports_and_constants'
  end

  super
end

Instance Attribute Details

#allow_empty_tests ⇒ Object (readonly)

Returns the value of attribute allow_empty_tests

Returns:

  • (Object) —

    the current value of allow_empty_tests



9
10
11
# File 'lib/archunit/common/fluentapi/check_options.rb', line 9

def allow_empty_tests
  @allow_empty_tests
end

#clear_cache ⇒ Object (readonly)

Returns the value of attribute clear_cache

Returns:

  • (Object) —

    the current value of clear_cache



9
10
11
# File 'lib/archunit/common/fluentapi/check_options.rb', line 9

def clear_cache
  @clear_cache
end

#dependency_analysis ⇒ Object (readonly)

Returns the value of attribute dependency_analysis

Returns:

  • (Object) —

    the current value of dependency_analysis



9
10
11
# File 'lib/archunit/common/fluentapi/check_options.rb', line 9

def dependency_analysis
  @dependency_analysis
end

#load_paths ⇒ Object (readonly)

Returns the value of attribute load_paths

Returns:

  • (Object) —

    the current value of load_paths



9
10
11
# File 'lib/archunit/common/fluentapi/check_options.rb', line 9

def load_paths
  @load_paths
end

#logging ⇒ Object (readonly)

Returns the value of attribute logging

Returns:

  • (Object) —

    the current value of logging



9
10
11
# File 'lib/archunit/common/fluentapi/check_options.rb', line 9

def logging
  @logging
end

Class Method Details

.resolve(value) ⇒ CheckOptions

Normalizes nil or an existing options value for terminal execution.

Parameters:

Returns:

Raises:

  • (ArgumentError)


15
16
17
18
19
20
# File 'lib/archunit/common/fluentapi/check_options.rb', line 15

def self.resolve(value)
  return new if value.nil?
  return value if value.is_a?(self)

  raise ArgumentError, 'options must be a CheckOptions value or nil'
end

Instance Method Details

#allow_empty_tests? ⇒ Boolean

Returns whether an empty subject selection is allowed.

Returns:

  • (Boolean) —

    whether an empty subject selection is allowed



43
44
45
# File 'lib/archunit/common/fluentapi/check_options.rb', line 43

def allow_empty_tests?
  allow_empty_tests
end

#clear_cache? ⇒ Boolean

Returns whether this check rebuilds the cached graph.

Returns:

  • (Boolean) —

    whether this check rebuilds the cached graph



48
49
50
# File 'lib/archunit/common/fluentapi/check_options.rb', line 48

def clear_cache?
  clear_cache
end

#constant_references? ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/archunit/common/fluentapi/check_options.rb', line 52

def constant_references?
  dependency_analysis == :imports_and_constants
end