Class: ArchUnit::Common::RegexFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/archunit/common/regex_factory.rb

Overview

The single construction point for user patterns and their matching targets.

Constant Summary collapse

TARGETED_EXCLUSIONS =
{
  in_path: :path,
  in_folder: :path_without_filename,
  with_name: :filename,
  for_classes_matching: :classname
}.freeze
DEFAULT_EXCLUSION_TARGETS =
{
  filename: %i[filename],
  path: %i[path filename],
  path_without_filename: %i[path path_without_filename filename],
  classname: %i[classname]
}.freeze

Class Method Summary collapse

Class Method Details

.classname_matcher(pattern, except: nil) ⇒ Object



36
37
38
# File 'lib/archunit/common/regex_factory.rb', line 36

def classname_matcher(pattern, except: nil)
  create_matcher(pattern, :classname, except:)
end

.exact_file_matcher(file_path, except: nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/archunit/common/regex_factory.rb', line 40

def exact_file_matcher(file_path, except: nil)
  unless file_path.is_a?(String) && !file_path.empty?
    raise ArgumentError, 'file_path must be a non-empty String'
  end

  normalized_path = file_path.tr('\\', '/')
  regexp = Regexp.new("\\A#{Regexp.escape(normalized_path)}\\z")
  exclusions = create_exclusion_filters(:path, except)
  Filter.new(regexp:, target: :path, matching: :exact, exclusions:)
end

.filename_matcher(pattern, except: nil) ⇒ Object



24
25
26
# File 'lib/archunit/common/regex_factory.rb', line 24

def filename_matcher(pattern, except: nil)
  create_matcher(pattern, :filename, except:)
end

.folder_matcher(pattern, except: nil) ⇒ Object



28
29
30
# File 'lib/archunit/common/regex_factory.rb', line 28

def folder_matcher(pattern, except: nil)
  create_matcher(pattern, :path_without_filename, except:)
end

.path_matcher(pattern, except: nil) ⇒ Object



32
33
34
# File 'lib/archunit/common/regex_factory.rb', line 32

def path_matcher(pattern, except: nil)
  create_matcher(pattern, :path, except:)
end