wallaby-core 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78bd6d5518f084f9d968a6e880148186171a5d9e57155750d695c50a6cf40b70
4
- data.tar.gz: b61387cb2a538b3befff1646adfdf2b9c207585b9bc0f4a42f56bb5e34465820
3
+ metadata.gz: 45b4a388789a1a5aa912f7c4fed3b70fd532976c9b6fc2ae9261a409b523ff33
4
+ data.tar.gz: 7012ee8417e1f08269ec5591218caf5dc46f21ea02d97a0cfbe8eab80f1e3211
5
5
  SHA512:
6
- metadata.gz: ce828c53a527a2dae0fe51aeb81e1a95d3282242f7b324de4f87542a6c670f90938612e0c263677cb3f2d68287fa182081a4a931762886d22467cdde0ec99d05
7
- data.tar.gz: 5a18a775749c109e769d285d09d188c49f370faf13bde75e3a0ca7626ec31b95060b35fa5d4fd3a44b7438d433ca9f56b5b7966aa3bcbc01b43ae7d7256ef21a
6
+ metadata.gz: 2cffdaa2781b5ae95be81f28f297ae005905f0a003a40df321f6b0109a287d3098513194cea03e0747b92eaf25405b72890663f53c9f913042f3501a3476966d
7
+ data.tar.gz: b9992869729df06ce388e42d8bfdd0cf14ef3b7da487d04195038c1154f496d4ae44c013376710e28664c28bb561c424b97aa252ad23efe943d9597451376612
@@ -23,14 +23,18 @@ module Wallaby
23
23
  # blank string will lead to NameError `wrong constant name`
24
24
  return if name.blank?
25
25
 
26
+ # [Performance] Caching the result for uninitialized constant
27
+ return (yield(name) if block_given?) if raising && Map.class_name_error_map[name] == :uninitialized
28
+
26
29
  # NOTE: DO NOT try to use `const_defined?` and `const_get` EVER.
27
30
  # Rails does all the class loading magics using `constantize`
28
31
  name.constantize
29
32
  rescue NameError => e
30
- raise if raising
31
-
32
- uninitialized = e.message.start_with?('uninitialized constant')
33
- raise unless uninitialized
33
+ if raising
34
+ Map.class_name_error_map[name] ||=
35
+ e.message.start_with?('uninitialized constant') ? :uninitialized : :name_error
36
+ raise e if Map.class_name_error_map[name] == :name_error
37
+ end
34
38
 
35
39
  # block to handle this missing constant, e.g. use a default class or log useful instruction
36
40
  yield(name) if block_given?
@@ -104,7 +104,6 @@ module Wallaby
104
104
  Deprecator.alert 'config.models.presence', from: '0.3.0', alternative: <<~INSTRUCTION
105
105
  Please use controller_class.models instead.
106
106
  INSTRUCTION
107
- @models ||= Models.new
108
107
  end
109
108
 
110
109
  # To globally configure the models that Wallaby should handle.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Wallaby
4
4
  module Core
5
- VERSION = '0.3.0' # :nodoc:
5
+ VERSION = '0.3.1' # :nodoc:
6
6
  end
7
7
  end
data/lib/wallaby/map.rb CHANGED
@@ -102,6 +102,14 @@ module Wallaby
102
102
  end
103
103
  end
104
104
 
105
+ class << self
106
+ # @!attribute [r] class_name_error_map
107
+ # Cache the class name error
108
+ def class_name_error_map
109
+ @class_name_error_map ||= {}
110
+ end
111
+ end
112
+
105
113
  class << self
106
114
  # Reset all the instance variables to nil
107
115
  def clear
@@ -33,7 +33,6 @@ module Wallaby
33
33
  @eager_load_paths ||=
34
34
  Rails.configuration.paths['app'].expanded
35
35
  .concat(Rails.configuration.eager_load_paths)
36
- .uniq
37
36
  end
38
37
 
39
38
  # @!attribute [w] 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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tianwen Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-23 00:00:00.000000000 Z
11
+ date: 2024-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel