Module: Constantinopolis::RailsReloader

Extended by:
RailsReloader
Included in:
RailsReloader
Defined in:
lib/constantinopolis/rails_reloader.rb

Instance Method Summary collapse

Instance Method Details

#active_reloaderObject



26
27
28
29
30
31
32
# File 'lib/constantinopolis/rails_reloader.rb', line 26

def active_reloader
  case Rails.version[0]
  when '4' then ActionDispatch::Reloader
  when '5' then ActiveSupport::Reloader
  else raise 'Unsupported rails version!'
  end
end

#file_update_checkerObject



18
19
20
21
22
23
24
# File 'lib/constantinopolis/rails_reloader.rb', line 18

def file_update_checker
  case Rails.version[0]
  when '4' then ActiveSupport::FileUpdateChecker
  when '5' then Rails.application.config.file_watcher || ActiveSupport::FileUpdateChecker
  else raise 'Unsupported rails version!'
  end
end

#register(klass, yml) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/constantinopolis/rails_reloader.rb', line 5

def register(klass, yml)
  unless Rails.env.production?
    reloader = file_update_checker.new([yml]) do
      klass.reload!
    end
    Rails.application.reloaders << reloader

    active_reloader.to_prepare do
      reloader.execute_if_updated
    end
  end
end