Class: Lmkplz::FileFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/lmkplz/file_filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(only: nil, except: nil) ⇒ FileFilter

Returns a new instance of FileFilter.



3
4
5
6
7
8
9
10
11
12
13
14
# 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

Instance Method Details

#call(modified_raw, created_raw, removed_raw) {|paths| ... } ⇒ Object

Yields:

  • (paths)


16
17
18
19
20
21
22
23
24
25
26
27
# 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