The recheck_precompiled_assets plugin enables checking for the precompiled asset metadata file. You need to have already loaded the assets plugin with the :precompiled option and the file specified by the :precompiled option must already exist in order to use the recheck_precompiled_assets plugin.
Any time you want to check whether the precompiled asset metadata file has changed and should be reloaded, you can call the recheck_precompiled_assets class method. This method will check whether the file has changed, and reload it if it has. If you want to check for modifications on every request, you can use self.class.recheck_precompiled_assets inside your route block.
Classes and Modules
Public Class methods
configure(app)
[show source]
# File lib/roda/plugins/recheck_precompiled_assets.rb 58 def self.configure(app) 59 precompiled_file = app.assets_config.precompiled 60 prev_mtime = ::File.mtime(precompiled_file) 61 62 request_class = app::RodaRequest 63 mutex = request_class.instance_variable_get(:@_precompiled_assets_mutex) 64 # Unset the assets matchers, in case a frozen value is already set 65 request_class.instance_variable_set(:@assets_matchers, nil) 66 # Ensure the assets matchers is set and an unfrozen array, and get the underlying value 67 request_class.assets_matchers 68 assets_matchers = request_class.instance_variable_get(:@assets_matchers) 69 70 app.instance_exec do 71 _update_compiled_assets(_compiled_assets_initial_hash.replace(assets_config.compiled)) 72 73 define_singleton_method(:recheck_precompiled_assets) do 74 new_mtime = ::File.mtime(precompiled_file) 75 if new_mtime != prev_mtime 76 prev_mtime = new_mtime 77 assets_config.compiled.replace(_precompiled_asset_metadata(precompiled_file)) 78 79 # Replace the asset matchers, in case the new precompiled metadata uses different files. 80 new_assets_matchers = request_class.send(:_build_assets_matchers) 81 mutex.synchronize{assets_matchers.replace(new_assets_matchers)} 82 end 83 end 84 singleton_class.send(:alias_method, :recheck_precompiled_assets, :recheck_precompiled_assets) 85 end 86 end
load_dependencies(app)
[show source]
# File lib/roda/plugins/recheck_precompiled_assets.rb 50 def self.load_dependencies(app) 51 unless app.respond_to?(:assets_config) && app.assets_config.precompiled 52 raise RodaError, "must load assets plugin with precompiled option before loading recheck_precompiled_assets plugin" 53 end 54 # Set mutex before overriding a method that uses it 55 app::RodaRequest.instance_variable_set(:@_precompiled_assets_mutex, Mutex.new) 56 end