wallaby-core 0.2.9 → 0.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a4c5c82124d25468728fff204eb9676d05100615edd67d86839d7008f258b42
4
- data.tar.gz: fe635d3585a5ec4d5205d90147d5377cc4a3e52459790b75a91e842fa41cce62
3
+ metadata.gz: 0f1ac3bd8eff66540e6b9f6c6c7b1f569bffe58177134b70fde36bd5b9e3df82
4
+ data.tar.gz: ec78aac3194fe1dd051160d9f77695247213565260b1035d1aebd7acd84ea1a6
5
5
  SHA512:
6
- metadata.gz: 5fbf645d202fea16af664376a78177b9bf4bf6e6a1243e31be82f833d3cbb4dc5c5504208f583c596029bd1f7cb4a826417d8fe044725fa31df999868e3636b3
7
- data.tar.gz: f0e750484101ed6bad77a22b531a4dcf4c5a89a6379bc92078e4a63a20bd381c664c0b6a66f97f4f312eebd858ada6e49fe95739012fd2092bfa7cefc9cc2ac8
6
+ metadata.gz: d5b70441c58655aa2bd9aa49175f137e8680a78619c9a5236e560a912dc86995dba8597a60f54ad90ac3a80a074a4ddb8bfca346c8a73fa772edae8e63aa2fc9
7
+ data.tar.gz: 459f70f2d01dba201f7873b5a7fa61c33ea3cf8ff8824ea7d33f450878ddbb01242bf71887a3200229cfe44b3c0c70190e76ea165872fe43238e424ed5a0254e
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Wallaby
4
4
  module Core
5
- VERSION = '0.2.9' # :nodoc:
5
+ VERSION = '0.2.11' # :nodoc:
6
6
  end
7
7
  end
@@ -5,28 +5,27 @@ module Wallaby
5
5
  class Engine < ::Rails::Engine
6
6
  initializer 'wallaby.development.reload' do |_|
7
7
  # NOTE: Rails reload! will hit here
8
- # @see http://rmosolgo.github.io/blog/2017/04/12/watching-files-during-rails-development/
8
+ # @see https://rmosolgo.github.io/ruby/rails/2017/04/12/watching-files-during-rails-development.html
9
9
  config.to_prepare do
10
- if Rails.env.development? || Rails.configuration.eager_load
11
- Logger.debug 'Reloading after Rails\' reload...', sourcing: false
12
- Map.clear
13
- Preloader.require_all
14
- end
10
+ Map.clear
11
+ Preloader.clear
15
12
  end
16
13
  end
17
14
 
18
15
  config.before_eager_load do
19
- # NOTE: The models must be loaded before everything else
20
- Logger.debug 'Preload all `app/models` files.', sourcing: false
16
+ Logger.debug 'Preload all model files before everything else.', sourcing: false
21
17
  Preloader.require_models
22
18
  end
23
19
 
24
20
  config.after_initialize do
25
- # Load the rest files
26
- unless Rails.env.development? || Rails.configuration.eager_load
27
- Logger.debug 'Preload all other eager load files after initialize.', sourcing: false
28
- Preloader.require_all
29
- end
21
+ # Preload will be postponed to Map when `cache_classes` is set to false
22
+ next unless Rails.configuration.cache_classes
23
+ # Models are preloaded in `before_eager_load` block,
24
+ # therefore, it's not essential to preload all files Since Rails will do it
25
+ next if Rails.configuration.eager_load
26
+
27
+ Logger.debug 'Preload all files in model first and non-model last order', sourcing: false
28
+ Preloader.require_all
30
29
  end
31
30
  end
32
31
  end
data/lib/wallaby/map.rb CHANGED
@@ -17,7 +17,11 @@ module Wallaby
17
17
 
18
18
  # @return [Wallaby::ClassHash] { Model Class => {Wallaby::Mode} }
19
19
  def mode_map
20
- @mode_map ||= ModeMapper.execute(modes).freeze
20
+ @mode_map ||= begin
21
+ # NOTE: this is the point where all files should be required
22
+ Preloader.require_all
23
+ ModeMapper.execute(modes).freeze
24
+ end
21
25
  end
22
26
 
23
27
  # TODO: remove this method
@@ -11,21 +11,31 @@ module Wallaby
11
11
  class Preloader
12
12
  include ActiveModel::Model
13
13
 
14
- # Require all files
15
- # @see #all_file_paths
16
- def self.require_all
17
- new.all_file_paths.each(&method(:require_dependency))
18
- end
14
+ class << self
15
+ def clear
16
+ @all_required = nil
17
+ end
18
+
19
+ # Require all files
20
+ # @see #all_file_paths
21
+ def require_all
22
+ return if @all_required
23
+
24
+ @all_required = true
25
+ Logger.debug 'Loading all files', sourcing: false
26
+ new.all_file_paths.each(&method(:require_dependency))
27
+ end
19
28
 
20
- # Require models under {Wallaby::Configuration#model_paths}
21
- # @see #model_file_paths
22
- def self.require_models
23
- new.model_file_paths.each(&method(:require_dependency))
29
+ # Require models under {Wallaby::Configuration#model_paths}
30
+ # @see #model_file_paths
31
+ def require_models
32
+ new.model_file_paths.each(&method(:require_dependency))
33
+ end
24
34
  end
25
35
 
26
36
  # @return [Array<String>] all files under **Rails.configuration.eager_load_paths**
27
37
  def all_file_paths
28
- sort all_eager_load_file_paths
38
+ sort(all_eager_load_file_paths)
29
39
  end
30
40
 
31
41
  # @return [Array<String>] model files under {Wallaby::Configuration#model_paths}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wallaby-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tian Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-19 00:00:00.000000000 Z
11
+ date: 2024-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel