class Lmkplz::FileFilter

Public Class Methods

new(only: nil, except: nil) click to toggle source
# File lib/lmkplz/file_filter.rb, line 3
def initialize(only: nil, except: nil)
  @matcher =
    if only && except
      raise "`only` and `except` params are mutually exclusive"
    elsif only
      -> (path) { path =~ only }
    elsif except
      -> (path) { path !~ except }
    else
      -> (_path) { true }
    end
end

Public Instance Methods

call(modified_raw, created_raw, removed_raw) { |*paths| ... } click to toggle source
# File lib/lmkplz/file_filter.rb, line 16
def call(modified_raw, created_raw, removed_raw)
  paths =
    [modified_raw, created_raw, removed_raw]
      .map(&method(:match_or_empty))
      .map(&method(:empty_to_nil))

  if paths.none?
    return
  end

  yield(*paths)
end

Private Instance Methods

empty_to_nil(path) click to toggle source
# File lib/lmkplz/file_filter.rb, line 39
def empty_to_nil(path)
  if path == ""
    nil
  else
    path
  end
end
match_or_empty(path) click to toggle source
# File lib/lmkplz/file_filter.rb, line 31
def match_or_empty(path)
  if @matcher.call(path)
    path
  else
    ""
  end
end