123456789_123456789_123456789_123456789_123456789_

Class: ActiveSupport::Reloader

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: ActiveSupport::ExecutionWrapper
Defined in: activesupport/lib/active_support/reloader.rb

Overview

This class defines several callbacks:

to_prepare -- Run once at application startup, and also from
{to_run}.

to_run -- Run before a work run that is reloading. If
{reload_classes_only_on_change} is true (the default), the class
unload will have already occurred.

to_complete -- Run after a work run that has reloaded. If
{reload_classes_only_on_change} is false, the class unload will
have occurred after the work run, but before this callback.

before_class_unload -- Run immediately before the classes are
unloaded.

after_class_unload -- Run immediately after the classes are
unloaded.

Constant Summary

Callbacks - Included

CALLBACK_FILTER_TYPES

ExecutionWrapper - Inherited

Null

Class Attribute Summary

Class Method Summary

ExecutionWrapper - Inherited

.register_hook

Register an object to be invoked during both the run and complete steps.

.run!

Run this execution.

.to_complete, .to_run,
.wrap

Perform the work in the supplied block as an execution.

.active_key, .error_reporter, .perform

DescendantsTracker - Inherited

Instance Attribute Summary

Instance Method Summary

ExecutionWrapper - Inherited

#complete!

Complete this in-flight execution.

#hook_state, #complete, #run, #run!

Callbacks - Included

#run_callbacks

Runs the callbacks for the given event.

#halted_callback_hook

A hook invoked every time a before callback is halted.

Constructor Details

.newReloader

[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 99

def initialize
  super
  @locked = false
end

Class Attribute Details

.check (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 85

class_attribute :check, default: lambda { false }

.check?Boolean (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 85

class_attribute :check, default: lambda { false }

.executor (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 84

class_attribute :executor, default: Executor

.executor?Boolean (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 84

class_attribute :executor, default: Executor

Class Method Details

.after_class_unload(*args, &block)

Registers a callback that will run immediately after the classes are unloaded.

[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 44

def self.after_class_unload(*args, &block)
  set_callback(:class_unload, :after, *args, &block)
end

.before_class_unload(*args, &block)

Registers a callback that will run immediately before the classes are unloaded.

[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 39

def self.before_class_unload(*args, &block)
  set_callback(:class_unload, *args, &block)
end

.check!

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 87

def self.check! # :nodoc:
  @should_reload ||= check.call
end

.prepare!

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 95

def self.prepare! # :nodoc:
  new.run_callbacks(:prepare)
end

.reload!

Initiate a manual reload

[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 51

def self.reload!
  executor.wrap do
    new.tap do |instance|
      instance.run!
    ensure
      instance.complete!
    end
  end
  prepare!
end

.reloaded!

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 91

def self.reloaded! # :nodoc:
  @should_reload = false
end

.run!(reset: false)

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 62

def self.run!(reset: false) # :nodoc:
  if check!
    super
  else
    Null
  end
end

.to_prepare(*args, &block)

Registers a callback that will run once at application startup and every time the code is reloaded.

[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 34

def self.to_prepare(*args, &block)
  set_callback(:prepare, *args, &block)
end

.wrap(**kwargs)

Run the supplied block as a work unit, reloading code as needed

[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 71

def self.wrap(**kwargs)
  return yield if active?

  executor.wrap(**kwargs) do
    instance = run!
    begin
      yield
    ensure
      instance.complete!
    end
  end
end

Instance Attribute Details

#check (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 85

class_attribute :check, default: lambda { false }

#check?Boolean (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 85

class_attribute :check, default: lambda { false }

#executor (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 84

class_attribute :executor, default: Executor

#executor?Boolean (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 84

class_attribute :executor, default: Executor

Instance Method Details

#class_unload!(&block)

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 126

def class_unload!(&block) # :nodoc:
  require_unload_lock!
  run_callbacks(:class_unload, &block)
end

#complete!

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 131

def complete! # :nodoc:
  super
  self.class.reloaded!
ensure
  release_unload_lock!
end

#release_unload_lock!

Release the unload lock if it has been previously obtained

[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 114

def release_unload_lock!
  if @locked
    @locked = false
    ActiveSupport::Dependencies.interlock.done_unloading
  end
end

#require_unload_lock!

Acquire the Dependencies::Interlock unload lock, ensuring it will be released automatically

[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 106

def require_unload_lock!
  unless @locked
    ActiveSupport::Dependencies.interlock.start_unloading
    @locked = true
  end
end

#run!

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/reloader.rb', line 121

def run! # :nodoc:
  super
  release_unload_lock!
end