Class: Wallaby::Preloader

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#eager_load_pathsArray<String, Pathname>

Returns:

  • (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'].expanded
      .concat(Rails.configuration.eager_load_paths)
end

#model_pathsArray<String>

Returns:

  • (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_modelsObject

Require models under Configuration#model_paths

See Also:



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_pathsArray<String>

Returns model files under Configuration#model_paths.

Returns:



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