class FileLine
Attributes
line_number[RW]
path[RW]
Public Class Methods
find_all(pattern, directory_path)
click to toggle source
# File lib/file_line.rb, line 10 def self.find_all(pattern, directory_path) grep_results = `grep -Irn "#{pattern}" #{directory_path} --exclude-dir="*.*.*"` grep_results.split("\n").map do |grep_hit| file_path, line_number, _ = grep_hit.split(":") line_number = line_number.to_i FileLine.new(line_number, file_path) end end
new(line_number, path)
click to toggle source
# File lib/file_line.rb, line 5 def initialize(line_number, path) @line_number = line_number @path = path end
Public Instance Methods
raw_contents()
click to toggle source
# File lib/file_line.rb, line 26 def raw_contents `sed -n #{line_number}p #{path}`.chomp end
update_filesystem!(new_contents)
click to toggle source
# File lib/file_line.rb, line 19 def update_filesystem!(new_contents) contents = File.read(path) splitted = contents.split("\n") splitted[line_number - 1] = new_contents File.write(path, splitted.join("\n")) end