Module: ArchUnit::Slices::Projection

Defined in:
lib/archunit/slices/projection/slice_projection.rb,
lib/archunit/slices/projection/slicing_projections.rb

Overview

Projections from file dependencies into architectural slices.

Defined Under Namespace

Classes: SliceProjection

Constant Summary collapse

CAPTURE =
'(**)'

Class Method Summary collapse

Class Method Details

.identityObject



15
16
17
# File 'lib/archunit/slices/projection/slicing_projections.rb', line 15

def identity
  SliceProjection.new { |path| path }
end

.slice_by_file_suffix(labeling) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/archunit/slices/projection/slicing_projections.rb', line 35

def slice_by_file_suffix(labeling)
  labels = immutable_suffix_labels(labeling)
  SliceProjection.new do |path|
    filename = path.split('/').last
    extension = File.extname(filename)
    stem = extension.empty? ? filename : filename.delete_suffix(extension)
    labels.find { |suffix, _label| stem.end_with?(suffix) }&.last
  end
end

.slice_by_pattern(pattern, except: nil) ⇒ Object



19
20
21
22
# File 'lib/archunit/slices/projection/slicing_projections.rb', line 19

def slice_by_pattern(pattern, except: nil)
  regexp = slice_pattern_regexp(pattern)
  slice_by_regex(regexp, except:)
end

.slice_by_regex(regexp, except: nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/archunit/slices/projection/slicing_projections.rb', line 24

def slice_by_regex(regexp, except: nil)
  regexp = immutable_regexp(regexp)
  selector = Common::RegexFactory.path_matcher('**', except:)
  SliceProjection.new do |path|
    next unless Common::PatternMatching.matches_pattern?(path, selector)

    match = regexp.match(path)
    match && non_empty_capture(match[1])
  end
end