Class: Pragmater::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/pragmater/runner.rb

Overview

Adds/removes pragma comments for files in given path.

Instance Method Summary collapse

Constructor Details

#initialize(path = ".", comments: [], whitelist: [], writer: Writer) ⇒ Runner

rubocop:disable Metrics/ParameterLists



7
8
9
10
11
12
# File 'lib/pragmater/runner.rb', line 7

def initialize path = ".", comments: [], whitelist: [], writer: Writer
  @path = Pathname path
  @comments = Array comments
  @whitelist = Array whitelist
  @writer = writer
end

Instance Method Details

#filesObject



14
15
16
17
# File 'lib/pragmater/runner.rb', line 14

def files
  return [] unless path.exist? && path.directory? && !whitelist.empty?
  Pathname.glob(%(#{path}/{#{whitelist.join ","}})).select(&:file?)
end

#run(action:) ⇒ Object



19
20
21
22
23
24
# File 'lib/pragmater/runner.rb', line 19

def run action:
  files.each do |file|
    writer.new(file, comments).public_send action
    yield file if block_given?
  end
end