Module: ArchUnit::Common::PatternMatching
- Defined in:
- lib/archunit/common/pattern_matching.rb
Overview
Generic matching operations. The Filter selects which part of a candidate is tested.
Class Method Summary collapse
- .extract_filename(path) ⇒ Object
- .matches_all_patterns?(file_path, filters, class_name: nil) ⇒ Boolean
- .matches_any_pattern?(file_path, filters, class_name: nil) ⇒ Boolean
- .matches_pattern?(file_path, filter, class_name: nil) ⇒ Boolean
- .normalize_path(path) ⇒ Object
- .path_without_filename(path) ⇒ Object
Class Method Details
.extract_filename(path) ⇒ Object
33 34 35 |
# File 'lib/archunit/common/pattern_matching.rb', line 33 def extract_filename(path) normalize_path(path).split('/').last.to_s end |
.matches_all_patterns?(file_path, filters, class_name: nil) ⇒ Boolean
21 22 23 |
# File 'lib/archunit/common/pattern_matching.rb', line 21 def matches_all_patterns?(file_path, filters, class_name: nil) filters.all? { |filter| matches_pattern?(file_path, filter, class_name:) } end |
.matches_any_pattern?(file_path, filters, class_name: nil) ⇒ Boolean
25 26 27 |
# File 'lib/archunit/common/pattern_matching.rb', line 25 def matches_any_pattern?(file_path, filters, class_name: nil) filters.any? { |filter| matches_pattern?(file_path, filter, class_name:) } end |
.matches_pattern?(file_path, filter, class_name: nil) ⇒ Boolean
11 12 13 14 15 16 17 18 19 |
# File 'lib/archunit/common/pattern_matching.rb', line 11 def matches_pattern?(file_path, filter, class_name: nil) validate_arguments(file_path, filter, class_name) target = target_string(file_path, filter.target, class_name) matches = regexp_matches?(filter, target) matches && filter.exclusions.none? do |exclusion| matches_pattern?(file_path, exclusion, class_name:) end end |
.normalize_path(path) ⇒ Object
29 30 31 |
# File 'lib/archunit/common/pattern_matching.rb', line 29 def normalize_path(path) path.tr('\\', '/') end |
.path_without_filename(path) ⇒ Object
37 38 39 40 41 |
# File 'lib/archunit/common/pattern_matching.rb', line 37 def path_without_filename(path) parts = normalize_path(path).split('/') parts.pop parts.join('/') end |