Module: Briefly::Rails::Reload

Defined in:
lib/briefly/rails/reload.rb

Overview

Lifecycle pack: clears the facade's memos at boot and on every code reload.

Usable on its own, for a facade that has no framework shortcuts but does memoize objects holding on to reloadable application classes:

Admin = Briefly.define { use Briefly::Rails::Reload }

The callback holds the facade for the process lifetime and cannot be deregistered. Install it on long-lived facades assigned to constants, not on facades built per request.

Class Method Summary collapse

Class Method Details

.install(builder) ⇒ Briefly::Builder

Parameters:

Returns:

Raises:



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/briefly/rails/reload.rb', line 24

def install(builder)
  facade = builder.facade
  return builder if facade.instance_variable_defined?(INSTALLED)

  app = ::Rails.application if defined?(::Rails)
  unless app.respond_to?(:reloader)
    raise Briefly::Error, "Briefly::Rails::Reload needs a booted application; use it from an initializer"
  end

  facade.instance_variable_set(INSTALLED, true)
  app.reloader.to_prepare { facade.clear_memos! }
  builder
end