Class: Wallaby::Preloader
- Inherits:
-
Object
- Object
- Wallaby::Preloader
- Includes:
- ActiveModel::Model
- Defined in:
- lib/wallaby/preloader.rb
Overview
Preload files for eager load paths.
As Wallaby is built upon the Map which will not be completed until all models and decorators/controllers/servicers/authorizers/paginators are loaded. Therefore, when Rails app is initialized, all files under eager load paths (mostly ‘app/*` folders), especially the files under `app/models`, need to be loaded before everything else.
Instance Attribute Summary collapse
Class Method Summary collapse
-
.require_models ⇒ Object
Require models under Configuration#model_paths.
Instance Method Summary collapse
-
#model_file_paths ⇒ Array<String>
Model files under Configuration#model_paths.
Instance Attribute Details
#eager_load_paths ⇒ Array<String, Pathname>
32 33 34 35 36 |
# File 'lib/wallaby/preloader.rb', line 32 def eager_load_paths # :nodoc: @eager_load_paths ||= Rails.configuration.paths['app']. .concat(Rails.configuration.eager_load_paths) end |
#model_paths ⇒ Array<String>
43 44 45 |
# File 'lib/wallaby/preloader.rb', line 43 def model_paths # :nodoc: @model_paths ||= Wallaby.configuration.model_paths end |
Class Method Details
.require_models ⇒ Object
Require models under Configuration#model_paths
17 18 19 |
# File 'lib/wallaby/preloader.rb', line 17 def require_models new.model_file_paths.each { |path| require_dependency(path) } # rubocop:disable Rails/RequireDependency, Lint/RedundantCopDisableDirective end |
Instance Method Details
#model_file_paths ⇒ Array<String>
Returns model files under Configuration#model_paths.
23 24 25 |
# File 'lib/wallaby/preloader.rb', line 23 def model_file_paths sort(all_eager_load_file_paths).select { |path| indexed(path) } end |