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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/method_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

rescue Errno::ENOENT => e
raise SourceNotFoundError, "Could not load source for #{name}: #{e.message}"
end
Expand Down