Class: RailsRenamer::ContentReplacer

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_renamer/content_replacer.rb

Class Method Summary collapse

Class Method Details

.find_and_replace_application_name(file_name, current_name, new_app_name) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rails_renamer/content_replacer.rb', line 3

def self.find_and_replace_application_name(file_name, current_name, new_app_name)
  begin
    file_stream = File.open(file_name, 'r+')
  rescue Errno::ENOENT => e
    puts "The specified file does not exist: #{file_name}"
    return
  end

  contents = file_stream.read

  contents.gsub!(current_name, new_app_name)

  File.truncate(file_name, 0)
  file_stream.write(contents)
  file_stream.close
  contents
end