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: [], includes: [], writer: Writer) ⇒ Runner

rubocop:disable Metrics/ParameterLists



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

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

Instance Method Details

#filesObject

rubocop:enable Metrics/ParameterLists



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

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

#run(action:) ⇒ Object



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

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