Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed file caching to allow live reloading of files #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

crismali
Copy link

@crismali crismali commented Jan 3, 2015

This way if you reload a file that defines a proc or a method the source updates. It also prevents SourceNotFound errors in case the proc or method definition moves within the file.

@@ -49,8 +49,7 @@ def self.comment_helper(source_location, name=nil)
# @return [Array<String>] the contents of the file
# @raise [SourceNotFoundError]
def self.lines_for(file_name, name=nil)
@lines_for_file ||= {}
@lines_for_file[file_name] ||= File.readlines(file_name)
File.readlines(file_name)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch, but i wonder how badly this slows things down in tools that use this functionality (like Pry).

Maybe it would be better to move to a helper object that does the memoization but which gets thrown away when it's no longer being used. Really silly of us (probably me) to put the memoization on the actual module itself!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How long should the files be memoized for?

@jairovm
Copy link

jairovm commented Jul 26, 2021

I'd be good to have a public API to delete a file from this hash, right now I'm doing this

MethodSource.instance_variable_get(:@lines_for_file).delete(absolute_path)

but it feels kind of weird 🤔, thanks guys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants