Class: Nandi::FileMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/nandi/file_matcher.rb

Constant Summary collapse

TIMESTAMP_REGEX =
/\A(?<operator>>|>=)?(?<timestamp>\d+)\z/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files:, spec:) ⇒ FileMatcher

Returns a new instance of FileMatcher.



11
12
13
14
# File 'lib/nandi/file_matcher.rb', line 11

def initialize(files:, spec:)
  @files = Set.new(files)
  @spec = spec
end

Class Method Details

.call(*args, **kwargs) ⇒ Object



7
8
9
# File 'lib/nandi/file_matcher.rb', line 7

def self.call(*args, **kwargs)
  new(*args, **kwargs).call
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nandi/file_matcher.rb', line 16

def call
  case spec
  when "all"
    Set.new(
      files.reject { |f| ignored_filenames.include?(File.basename(f)) },
    )
  when "git-diff"
    files.intersection(files_from_git_status)
  when TIMESTAMP_REGEX
    match_timestamp
  end
end