Class: ActiveSupport::Reloader

Inherits:
ExecutionWrapper show all
Defined in:
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

Constants inherited from ExecutionWrapper

ExecutionWrapper::Null

Constants included from Callbacks

Callbacks::CALLBACK_FILTER_TYPES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ExecutionWrapper

active?, inherited, register_hook, to_complete, to_run

Methods included from Callbacks

#run_callbacks

Methods included from Concern

#append_features, #class_methods, extended, #included

Constructor Details

#initializeReloader

Returns a new instance of Reloader.



90
91
92
93
# File 'lib/active_support/reloader.rb', line 90

def initialize
  super
  @locked = false
end

Class Method Details

.after_class_unload(*args, &block) ⇒ Object



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

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

.before_class_unload(*args, &block) ⇒ Object



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

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

.check!Object

:nodoc:



78
79
80
# File 'lib/active_support/reloader.rb', line 78

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

.prepare!Object

:nodoc:



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

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

.reload!Object

Initiate a manual reload



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/active_support/reloader.rb', line 44

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

.reloaded!Object

:nodoc:



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

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

.run!Object

:nodoc:



57
58
59
60
61
62
63
# File 'lib/active_support/reloader.rb', line 57

def self.run! # :nodoc:
  if check!
    super
  else
    Null
  end
end

.to_prepare(*args, &block) ⇒ Object



29
30
31
# File 'lib/active_support/reloader.rb', line 29

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

.wrapObject

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



66
67
68
69
70
# File 'lib/active_support/reloader.rb', line 66

def self.wrap
  executor.wrap do
    super
  end
end

Instance Method Details

#class_unload!(&block) ⇒ Object

:nodoc:



117
118
119
120
# File 'lib/active_support/reloader.rb', line 117

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

#complete!Object

:nodoc:



122
123
124
125
126
127
# File 'lib/active_support/reloader.rb', line 122

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

#release_unload_lock!Object

Release the unload lock if it has been previously obtained



105
106
107
108
109
110
# File 'lib/active_support/reloader.rb', line 105

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

#require_unload_lock!Object

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



97
98
99
100
101
102
# File 'lib/active_support/reloader.rb', line 97

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

#run!Object

:nodoc:



112
113
114
115
# File 'lib/active_support/reloader.rb', line 112

def run! # :nodoc:
  super
  release_unload_lock!
end