Module: ActiveReload

Defined in:
lib/active_reload.rb,
lib/active_reload/version.rb

Defined Under Namespace

Modules: ProcInspector Classes: Railtie

Constant Summary collapse

VERSION =
"0.6.1"

Class Method Summary collapse

Class Method Details

.proc_collectionObject



35
36
37
38
39
40
41
# File 'lib/active_reload.rb', line 35

def self.proc_collection
  if rails31?
    proc_source._cleanup_callbacks
  else
    proc_source._call_callbacks
  end
end

.proc_sourceObject



43
44
45
46
47
48
49
# File 'lib/active_reload.rb', line 43

def self.proc_source
  if rails31?
    ActionDispatch::Reloader
  else
    ActionDispatch::Callbacks
  end
end

.rails31?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/active_reload.rb', line 97

def self.rails31?
  rails3? && Rails::VERSION::MINOR == 1
end

.rails3?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/active_reload.rb', line 93

def self.rails3?
  Rails::VERSION::MAJOR == 3
end

.replace!Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/active_reload.rb', line 57

def self.replace!
  return unless replace?
  
  ActiveSupport::Notifications.instrument("active_reload.set_clear_dependencies_hook_replaced") do

    changed_at = Proc.new do
      ActiveSupport::Dependencies.autoload_paths.map do |p|
        Dir["#{p}/**/*.rb"].map{|f| File.mtime(f) }
      end.flatten.max
    end

    last_change = Time.now

    replace_proc do
      change = changed_at.call
      if change > last_change
        last_change = change
        ActiveSupport::Notifications.instrument("active_support.dependencies.clear") do
          ActiveSupport::DescendantsTracker.clear
          ActiveSupport::Dependencies.clear
        end
      end
    end
  end
end

.replace?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/active_reload.rb', line 31

def self.replace?
  !Rails.application.config.cache_classes && replace_proc?(proc_collection.last)
end

.replace_proc(&new) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/active_reload.rb', line 83

def self.replace_proc(&new)
  @replaced = proc_collection.pop
  if rails31?
    proc_source.to_prepare(&new)
    proc_source.__define_runner(:cleanup)
  else
    proc_source.before(&new)
  end
end

.replace_proc?(last) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
# File 'lib/active_reload.rb', line 51

def self.replace_proc?(last)
  last.respond_to?(:raw_filter) &&
  last.raw_filter.is_a?(Proc) &&
  last.raw_filter.extend(ProcInspector).source?("railties.*/lib/rails/application/bootstrap.rb")
end