module Roda::RodaPlugins::RecheckPrecompiledAssets

  1. lib/roda/plugins/recheck_precompiled_assets.rb

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.

Methods

Public Class

  1. configure
  2. load_dependencies

Public Class methods

configure(app)
[show source]
   # File lib/roda/plugins/recheck_precompiled_assets.rb
56 def self.configure(app)
57   precompiled_file = app.assets_opts[:precompiled]
58   prev_mtime = ::File.mtime(precompiled_file)
59   app.instance_exec do
60     opts[:assets] = opts[:assets].merge(:compiled=>_compiled_assets_initial_hash.replace(assets_opts[:compiled])).freeze
61 
62     define_singleton_method(:recheck_precompiled_assets) do
63       new_mtime = ::File.mtime(precompiled_file)
64       if new_mtime != prev_mtime
65         prev_mtime = new_mtime
66         assets_opts[:compiled].replace(_precompiled_asset_metadata(precompiled_file))
67 
68         # Unset the cached asset matchers, so new ones will be generated.
69         # This is needed in case the new precompiled metadata uses
70         # different files.
71         app::RodaRequest.instance_variable_set(:@assets_matchers, nil)
72       end
73     end
74     singleton_class.send(:alias_method, :recheck_precompiled_assets, :recheck_precompiled_assets)
75   end
76 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_opts) && app.assets_opts[:precompiled]
52     raise RodaError, "must load assets plugin with precompiled option before loading recheck_precompiled_assets plugin"
53   end
54 end