# frozen_string_literal: truerequire"dry/files"path="path/to/file.rb"files=Dry::Files.new# adds a new line at the top of the filefiles.unshift(path,"# frozen_string_literal: true")# adds a new line at the bottom of the filefiles.append(path,"__END__")# replace first line that match targetfiles.replace_first_line(path,"foo","bar")# replace the first match of foo, with bar# replace last line that match targetfiles.replace_last_line(path,"foo","bar")# replace the last match of foo, with bar# inject content before the first match of targetfiles.inject_line_before(path,"foo","abc")# inject abc before the first match of foo# inject content before the last match of targetfiles.inject_line_before_last(path,"foo","abc")# inject abc before the last match of foo# inject content after the first match of targetfiles.inject_line_after(path,"foo","def")# inject def after the first match of foo# inject content after the last match of targetfiles.inject_line_after_last(path,"foo","def")# inject def after the last match of foo# inject content as the first line of the matching code blockfiles.inject_line_at_block_top(path,"routes do","route")# inject route, right after the routes block opening# inject content as the last line of the matching code blockfiles.inject_line_at_block_bottom(path,"routes do","route")# inject route, right after the routes block ending# remove the first matching linefiles.remove_line(line,"foo")# removes the first line that matches foo# remove the first matching blockfiles.remove_block(line,"configure do")# removes the first block that matches configure