Class: Rage::CodeLoader
- Inherits:
-
Object
- Object
- Rage::CodeLoader
- Defined in:
- lib/rage/code_loader.rb
Instance Method Summary collapse
-
#initialize ⇒ CodeLoader
constructor
A new instance of CodeLoader.
-
#rails_mode_reload ⇒ Object
in Rails mode - reset the routes; everything else will be done by Rails.
-
#reload ⇒ Object
in standalone mode - reload the code and the routes.
- #reloading? ⇒ Boolean
- #setup ⇒ Object
Constructor Details
#initialize ⇒ CodeLoader
Returns a new instance of CodeLoader.
6 7 8 |
# File 'lib/rage/code_loader.rb', line 6 def initialize @reloading = false end |
Instance Method Details
#rails_mode_reload ⇒ Object
in Rails mode - reset the routes; everything else will be done by Rails
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rage/code_loader.rb', line 43 def rails_mode_reload return if @loader @reloading = true Rage.__router.reset_routes unless Rage.autoload?(:Cable) # the `Cable` component is loaded Rage::Cable.__router.reset end end |
#reload ⇒ Object
in standalone mode - reload the code and the routes
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rage/code_loader.rb', line 28 def reload return unless @loader @reloading = true @loader.reload Rage.__router.reset_routes load("#{Rage.root}/config/routes.rb") unless Rage.autoload?(:Cable) # the `Cable` component is loaded Rage::Cable.__router.reset end end |
#reloading? ⇒ Boolean
54 55 56 |
# File 'lib/rage/code_loader.rb', line 54 def reloading? @reloading end |
#setup ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rage/code_loader.rb', line 10 def setup @loader = Zeitwerk::Loader.new autoload_path = "#{Rage.root}/app" enable_reloading = Rage.env.development? enable_eager_loading = !Rage.env.development? && !Rage.env.test? @loader.push_dir(autoload_path) # The first level of directories in app directory won't be treated as modules # e.g. app/controllers/pages_controller.rb will be linked to PagesController class # instead of Controllers::PagesController @loader.collapse("#{Rage.root}/app/*") @loader.enable_reloading if enable_reloading @loader.setup @loader.eager_load if enable_eager_loading end |