Class: PryToggle::Service
- Inherits:
-
Object
- Object
- PryToggle::Service
- Defined in:
- lib/pry_toggle/service.rb
Instance Method Summary collapse
Instance Method Details
#execute ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/pry_toggle/service.rb', line 6 def execute File.open(tmp_file_path, 'w') do |d| File.open(abs_file_path, 'r') do |o| o.each.with_index(1) do |line, i| if (line == str) else d << str if i == line_num d << line end d << str if line =~ %r|def( +)#{mth_name}| end end end FileUtils.mv(tmp_file_path, abs_file_path) rescue Errno::ENOENT puts "No such file - #{origin_path}" ensure FileUtils.rm_f(tmp_file_path) end |