Module: Semmy::Files

Defined in:
lib/semmy/files.rb

Class Method Summary collapse

Class Method Details

.rewrite(path, update) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/semmy/files.rb', line 5

def rewrite(path, update)
  content = File.binread(path)
  updated_content = update.call(content)

  File.open(path, 'wb') do |file|
    file.write(updated_content)
  end
end

.rewrite_all(glob, update) ⇒ Object



14
15
16
17
18
# File 'lib/semmy/files.rb', line 14

def rewrite_all(glob, update)
  Dir.glob(glob) do |path|
    rewrite(path, update)
  end
end