diff options
author | Yoshiyuki Hirano <yhirano@me.com> | 2021-11-17 12:25:47 +0900 |
---|---|---|
committer | Yoshiyuki Hirano <yhirano@me.com> | 2021-11-17 12:44:30 +0900 |
commit | 2d7ea4448bb2fd2b8fcfe153358a0e550e4973f0 (patch) | |
tree | f073c8b35199f975d086a85ba8fde48e9d1055b2 /lib | |
parent | e7ec1370b4c4283c2b6876977a0462a7634f7935 (diff) | |
download | method_source-2d7ea4448bb2fd2b8fcfe153358a0e550e4973f0.tar.gz |
Add MethodSource.clear_cache
We often need to clear cache.
For example, in web application development, when we changed source code, we would like the change applied to the app server without reboot.
In the case of a Rails application, this requires the following configuration:
```ruby
Rails.application.configure do
config.to_prepare do
MethodSource.instance_variable_set(:@lines_for_file, {})
end
end
```
It seems so ugly, isn't it? So I feel we need to add `MethodSource.clear_cache` interface.
```diff
Rails.application.configure do
config.to_prepare do
- MethodSource.instance_variable_set(:@lines_for_file, {})
+ MethodSource.clear_cache
end
end
```
Diffstat (limited to 'lib')
-rw-r--r-- | lib/method_source.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/method_source.rb b/lib/method_source.rb index 3c6086b..ffd79ad 100644 --- a/lib/method_source.rb +++ b/lib/method_source.rb @@ -55,6 +55,11 @@ module MethodSource raise SourceNotFoundError, "Could not load source for #{name}: #{e.message}" end + # Clear cache. + def self.clear_cache + @lines_for_file = {} + end + # @deprecated — use MethodSource::CodeHelpers#complete_expression? def self.valid_expression?(str) complete_expression?(str) |