Class: Rage::CodeLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/code_loader.rb

Instance Method Summary collapse

Constructor Details

#initializeCodeLoader

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_reloadObject

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

#reloadObject

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

Returns:

  • (Boolean)


54
55
56
# File 'lib/rage/code_loader.rb', line 54

def reloading?
  @reloading
end

#setupObject



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