Module: Roda::RodaPlugins::RecheckPrecompiledAssets

Defined in:
lib/roda/plugins/recheck_precompiled_assets.rb

Overview

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.

Defined Under Namespace

Modules: ClassMethods, RequestClassMethods Classes: CompiledAssetsHash

Class Method Summary collapse

Class Method Details

.configure(app) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/roda/plugins/recheck_precompiled_assets.rb', line 56

def self.configure(app)
  precompiled_file = app.assets_opts[:precompiled]
  prev_mtime = ::File.mtime(precompiled_file)
  app.instance_exec do
    opts[:assets] = opts[:assets].merge(:compiled=>_compiled_assets_initial_hash.replace(assets_opts[:compiled])).freeze

    define_singleton_method(:recheck_precompiled_assets) do
      new_mtime = ::File.mtime(precompiled_file)
      if new_mtime != prev_mtime
        prev_mtime = new_mtime
        assets_opts[:compiled].replace((precompiled_file))

        # Unset the cached asset matchers, so new ones will be generated.
        # This is needed in case the new precompiled metadata uses
        # different files.
        app::RodaRequest.instance_variable_set(:@assets_matchers, nil)
      end
    end
    singleton_class.send(:alias_method, :recheck_precompiled_assets, :recheck_precompiled_assets)
  end
end

.load_dependencies(app) ⇒ Object



50
51
52
53
54
# File 'lib/roda/plugins/recheck_precompiled_assets.rb', line 50

def self.load_dependencies(app)
  unless app.respond_to?(:assets_opts) && app.assets_opts[:precompiled]
    raise RodaError, "must load assets plugin with precompiled option before loading recheck_precompiled_assets plugin"
  end
end