nshki / chusaku

Annotate your Rails controllers with route info.
https://rubygems.org/gems/chusaku
MIT License
87 stars 4 forks source link

Fix invalid file content trails #14

Closed nshki closed 4 years ago

nshki commented 4 years ago

Outcome

Files that end up shorter than they were originally will no longer have "remnants" of what the previous contents were.

Problem

Due to Chusaku using File.open(file, 'r+'), files that ended up shorter as a result of the executable kept old file contents trailing after the newly written contents.

Solution

Switch to using w mode with File.

nshki commented 4 years ago

@justinshaw I'd like you to take a look at this branch as the original reporter of the issue to see if it works for the project that you're using Chusaku on.

You should be able to swap out the appropriate line in your Gemfile with:

gem 'chusaku', git: 'git://github.com/nshki/chusaku.git', branch: 'nshki/fix-invalid-trails'

Then give it another whirl with:

$ bundle exec chusaku
justinshaw commented 4 years ago

In order to test this, I checked out a controller from before changes to the routes and ran chusaku while leaving routes.rb in place. I didn't encounter the issue again, so ship it!