Class: Rage::CodeLoader
- Inherits:
-
Object
- Object
- Rage::CodeLoader
- Defined in:
- lib/rage/code_loader.rb
Instance Method Summary collapse
- #check_updated! ⇒ Object
-
#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 9 |
# File 'lib/rage/code_loader.rb', line 6 def initialize @reloading = false @autoload_path = Rage.root.join("app") end |
Instance Method Details
#check_updated! ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rage/code_loader.rb', line 56 def check_updated! current_watched = @autoload_path.glob("**/*.rb") + Rage.root.glob("config/routes.rb") + Rage.root.glob("config/openapi_components.*") current_update_at = current_watched.max_by { |path| path.exist? ? path.mtime.to_f : 0 }&.mtime.to_f return false if !@last_watched && !@last_update_at current_watched.size != @last_watched.size || current_update_at != @last_update_at ensure @last_watched, @last_update_at = current_watched, current_update_at end |
#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 |
# File 'lib/rage/code_loader.rb', line 43 def rails_mode_reload return if @loader @reloading = true Rage.__router.reset_routes reload_components end |
#reload ⇒ Object
in standalone mode - reload the code and the routes
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rage/code_loader.rb', line 30 def reload return unless @loader @reloading = true @loader.reload Rage.__router.reset_routes load("#{Rage.root}/config/routes.rb") reload_components end |
#reloading? ⇒ Boolean
52 53 54 |
# File 'lib/rage/code_loader.rb', line 52 def reloading? @reloading end |
#setup ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rage/code_loader.rb', line 11 def setup @loader = Zeitwerk::Loader.new enable_reloading = Rage.env.development? enable_eager_loading = !Rage.env.development? && !Rage.env.test? @loader.push_dir(@autoload_path.to_s) # 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 configure_components end |