wallaby-core 0.2.11 → 0.3.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/wallaby/resources_controller.rb +20 -7
  3. data/app/security/ability.rb +1 -1
  4. data/config/routes.rb +21 -14
  5. data/lib/adaptors/wallaby/custom/default_provider.rb +1 -1
  6. data/lib/adaptors/wallaby/custom/model_decorator.rb +5 -17
  7. data/lib/adaptors/wallaby/custom/model_finder.rb +3 -3
  8. data/lib/adaptors/wallaby/custom/model_pagination_provider.rb +1 -1
  9. data/lib/adaptors/wallaby/custom/model_service_provider.rb +1 -1
  10. data/lib/authorizers/wallaby/cancancan_authorization_provider.rb +12 -5
  11. data/lib/authorizers/wallaby/default_authorization_provider.rb +10 -1
  12. data/lib/authorizers/wallaby/model_authorizer.rb +41 -16
  13. data/lib/authorizers/wallaby/pundit_authorization_provider.rb +22 -8
  14. data/lib/concerns/wallaby/application_concern.rb +41 -71
  15. data/lib/concerns/wallaby/authentication_concern.rb +29 -127
  16. data/lib/concerns/wallaby/authorizable.rb +14 -57
  17. data/lib/concerns/wallaby/baseable.rb +24 -57
  18. data/lib/concerns/wallaby/configurable.rb +416 -0
  19. data/lib/concerns/wallaby/decoratable.rb +29 -60
  20. data/lib/concerns/wallaby/engineable.rb +29 -46
  21. data/lib/concerns/wallaby/fieldable.rb +45 -56
  22. data/lib/concerns/wallaby/paginatable.rb +20 -51
  23. data/lib/concerns/wallaby/prefixable.rb +24 -4
  24. data/lib/concerns/wallaby/resourcable.rb +130 -72
  25. data/lib/concerns/wallaby/resources_concern.rb +205 -305
  26. data/lib/concerns/wallaby/servicable.rb +8 -48
  27. data/lib/concerns/wallaby/urlable.rb +69 -0
  28. data/lib/decorators/wallaby/resource_decorator.rb +91 -34
  29. data/lib/errors/wallaby/class_not_found.rb +1 -2
  30. data/lib/errors/wallaby/forbidden.rb +1 -2
  31. data/lib/errors/wallaby/general_error.rb +1 -1
  32. data/lib/errors/wallaby/invalid_error.rb +1 -2
  33. data/lib/errors/wallaby/method_removed.rb +5 -0
  34. data/lib/errors/wallaby/model_not_found.rb +1 -2
  35. data/lib/errors/wallaby/not_authenticated.rb +1 -2
  36. data/lib/errors/wallaby/not_found.rb +1 -2
  37. data/lib/errors/wallaby/not_implemented.rb +1 -2
  38. data/lib/errors/wallaby/resource_not_found.rb +1 -2
  39. data/lib/errors/wallaby/unprocessable_entity.rb +1 -2
  40. data/lib/fields/wallaby/all_fields.rb +63 -0
  41. data/lib/forms/wallaby/form_builder.rb +1 -1
  42. data/lib/generators/wallaby/engine/application_generator.rb +33 -0
  43. data/lib/generators/wallaby/engine/authorizer/USAGE +20 -0
  44. data/lib/generators/wallaby/engine/authorizer/authorizer_generator.rb +19 -0
  45. data/lib/generators/wallaby/engine/authorizer/templates/authorizer.rb.erb +35 -0
  46. data/lib/generators/wallaby/engine/controller/USAGE +20 -0
  47. data/lib/generators/wallaby/engine/controller/controller_generator.rb +23 -0
  48. data/lib/generators/wallaby/engine/controller/templates/controller.rb.erb +130 -0
  49. data/lib/generators/wallaby/engine/decorator/USAGE +20 -0
  50. data/lib/generators/wallaby/engine/decorator/decorator_generator.rb +19 -0
  51. data/lib/generators/wallaby/engine/decorator/templates/decorator.rb.erb +5 -0
  52. data/lib/generators/wallaby/engine/install/USAGE +19 -0
  53. data/lib/generators/wallaby/engine/install/install_generator.rb +91 -0
  54. data/lib/generators/wallaby/engine/install/templates/application_authorizer.rb.erb +37 -0
  55. data/lib/generators/wallaby/engine/install/templates/application_controller.rb.erb +173 -0
  56. data/lib/generators/wallaby/engine/install/templates/application_decorator.rb.erb +7 -0
  57. data/lib/generators/wallaby/engine/install/templates/application_paginator.rb.erb +27 -0
  58. data/lib/generators/wallaby/engine/install/templates/application_servicer.rb.erb +47 -0
  59. data/lib/generators/wallaby/engine/install/templates/initializer.rb.erb +16 -0
  60. data/lib/generators/wallaby/engine/paginator/USAGE +20 -0
  61. data/lib/generators/wallaby/engine/paginator/paginator_generator.rb +19 -0
  62. data/lib/generators/wallaby/engine/paginator/templates/paginator.rb.erb +25 -0
  63. data/lib/generators/wallaby/engine/servicer/USAGE +20 -0
  64. data/lib/generators/wallaby/engine/servicer/servicer_generator.rb +19 -0
  65. data/lib/generators/wallaby/engine/servicer/templates/servicer.rb.erb +45 -0
  66. data/lib/helpers/wallaby/application_helper.rb +10 -59
  67. data/lib/helpers/wallaby/base_helper.rb +11 -11
  68. data/lib/helpers/wallaby/configuration_helper.rb +36 -4
  69. data/lib/helpers/wallaby/form_helper.rb +1 -1
  70. data/lib/helpers/wallaby/index_helper.rb +19 -9
  71. data/lib/helpers/wallaby/links_helper.rb +18 -85
  72. data/lib/helpers/wallaby/resources_helper.rb +39 -7
  73. data/lib/helpers/wallaby/secure_helper.rb +20 -19
  74. data/lib/interfaces/wallaby/mode.rb +8 -8
  75. data/lib/interfaces/wallaby/model_authorization_provider.rb +23 -22
  76. data/lib/interfaces/wallaby/model_decorator.rb +36 -48
  77. data/lib/interfaces/wallaby/model_finder.rb +3 -3
  78. data/lib/interfaces/wallaby/model_pagination_provider.rb +2 -6
  79. data/lib/interfaces/wallaby/model_service_provider.rb +4 -4
  80. data/lib/paginators/wallaby/model_paginator.rb +1 -1
  81. data/lib/responders/wallaby/json_api_responder.rb +10 -5
  82. data/lib/responders/wallaby/resources_responder.rb +10 -3
  83. data/lib/routes/wallaby/engines/base_route.rb +78 -0
  84. data/lib/routes/wallaby/engines/custom_app_route.rb +92 -0
  85. data/lib/routes/wallaby/engines/engine_route.rb +77 -0
  86. data/lib/routes/wallaby/resources_router.rb +100 -45
  87. data/lib/servicers/wallaby/model_servicer.rb +13 -13
  88. data/lib/services/wallaby/authorizer_finder.rb +23 -0
  89. data/lib/services/wallaby/class_finder.rb +42 -0
  90. data/lib/services/wallaby/controller_finder.rb +29 -0
  91. data/lib/services/wallaby/decorator_finder.rb +34 -0
  92. data/lib/services/wallaby/default_models_excluder.rb +45 -0
  93. data/lib/services/wallaby/engine_name_finder.rb +14 -11
  94. data/lib/services/wallaby/engine_url_for.rb +82 -37
  95. data/lib/services/wallaby/fields_regulator.rb +34 -0
  96. data/lib/services/wallaby/map/mode_mapper.rb +5 -5
  97. data/lib/services/wallaby/map/model_class_mapper.rb +1 -1
  98. data/lib/services/wallaby/model_class_filter.rb +29 -0
  99. data/lib/services/wallaby/paginator_finder.rb +24 -0
  100. data/lib/services/wallaby/prefixes_builder.rb +49 -8
  101. data/lib/services/wallaby/servicer_finder.rb +31 -0
  102. data/lib/services/wallaby/sorting/hash_builder.rb +9 -0
  103. data/lib/services/wallaby/sorting/link_builder.rb +7 -10
  104. data/lib/services/wallaby/sorting/next_builder.rb +1 -12
  105. data/lib/services/wallaby/sorting/single_builder.rb +1 -1
  106. data/lib/support/action_dispatch/routing/mapper.rb +29 -4
  107. data/lib/utils/wallaby/field_utils.rb +9 -8
  108. data/lib/utils/wallaby/inflector.rb +94 -0
  109. data/lib/utils/wallaby/locale.rb +2 -2
  110. data/lib/utils/wallaby/module_utils.rb +3 -10
  111. data/lib/utils/wallaby/utils.rb +21 -14
  112. data/lib/wallaby/class_array.rb +18 -13
  113. data/lib/wallaby/class_hash.rb +16 -14
  114. data/lib/wallaby/classifier.rb +4 -2
  115. data/lib/wallaby/configuration/features.rb +8 -2
  116. data/lib/wallaby/configuration/mapping.rb +66 -112
  117. data/lib/wallaby/configuration/metadata.rb +15 -12
  118. data/lib/wallaby/configuration/models.rb +27 -25
  119. data/lib/wallaby/configuration/pagination.rb +15 -19
  120. data/lib/wallaby/configuration/security.rb +88 -80
  121. data/lib/wallaby/configuration/sorting.rb +15 -17
  122. data/lib/wallaby/configuration.rb +58 -23
  123. data/lib/wallaby/constants.rb +21 -13
  124. data/lib/wallaby/core/version.rb +1 -1
  125. data/lib/wallaby/core.rb +34 -10
  126. data/lib/wallaby/deprecator.rb +81 -0
  127. data/lib/wallaby/engine.rb +1 -18
  128. data/lib/wallaby/guesser.rb +45 -0
  129. data/lib/wallaby/logger.rb +35 -13
  130. data/lib/wallaby/map.rb +11 -88
  131. data/lib/wallaby/preloader.rb +8 -28
  132. metadata +113 -14
  133. data/config/locales/wallaby_class.en.yml +0 -9
  134. data/lib/concerns/wallaby/defaultable.rb +0 -38
  135. data/lib/concerns/wallaby/shared_helpers.rb +0 -22
  136. data/lib/services/wallaby/map/model_class_collector.rb +0 -49
  137. data/lib/services/wallaby/type_renderer.rb +0 -40
  138. data/lib/utils/wallaby/model_utils.rb +0 -52
  139. data/lib/utils/wallaby/test_utils.rb +0 -34
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wallaby
4
+ # Deprecation log for methods
5
+ class Deprecator
6
+ include ActiveModel::Model
7
+
8
+ # @!attribute method_instance
9
+ # @return [Method]
10
+ attr_accessor :method_instance
11
+ # @!attribute from
12
+ # @return [String]
13
+ attr_accessor :from
14
+ # @!attribute mod
15
+ # @return [Class]
16
+ attr_accessor :mod
17
+ # @!attribute alternative
18
+ # @return [Method]
19
+ attr_accessor :alternative
20
+
21
+ # Log an warning deprecation message or raise {MethodRemoved} when the given method is obsolete.
22
+ # @param method_instance [Method] deprecated/obsolete method
23
+ # @param from [String] from/since version
24
+ # @param mod [Class] class name which has `VERSION` constants
25
+ # @param alternative [Method] method to replace the deprecated/obsolete one
26
+ # @see #alert
27
+ def self.alert(method_instance, from:, mod: Core, alternative: nil)
28
+ new(
29
+ method_instance: method_instance, from: from, mod: mod, alternative: alternative
30
+ ).alert
31
+ end
32
+
33
+ # @raise [MethodRemoved] when given method is obsolete
34
+ def alert
35
+ # if current version is larger than from version
36
+ already = Gem::Version.new(mod_version) >= Gem::Version.new(from)
37
+ raise MethodRemoved, obsolete_message if already
38
+
39
+ Logger.warn deprecated_message, sourcing: 2
40
+ end
41
+
42
+ protected
43
+
44
+ def obsolete_message
45
+ "ERROR: #{full method_instance} is removed since #{mod_name} #{from}. #{alternative_message}"
46
+ end
47
+
48
+ def deprecated_message
49
+ "DEPRECATED: #{full method_instance} will be removed from #{mod_name} #{from}. #{alternative_message}"
50
+ end
51
+
52
+ def alternative_message
53
+ return "Please use #{full alternative} instead." if alternative.is_a? Method
54
+
55
+ alternative.to_s
56
+ end
57
+
58
+ def mod_name
59
+ return mod unless mod.is_a? Module
60
+
61
+ mod.name.underscore.gsub SLASH, HYPHEN
62
+ end
63
+
64
+ def mod_version
65
+ return mod unless mod.is_a? Module
66
+
67
+ mod::VERSION
68
+ end
69
+
70
+ # @param method_instance [Method]
71
+ # @return [String] `Class.class_method` or `Class#instance_method`
72
+ def full(method_instance)
73
+ return method_instance unless method_instance.is_a? Method
74
+
75
+ owner = method_instance.owner
76
+ is_klass_method = owner.singleton_class?
77
+ klass = is_klass_method ? owner.to_s[8..-2] : owner.name
78
+ "#{klass}#{is_klass_method ? DOT : HASH}#{method_instance.name}"
79
+ end
80
+ end
81
+ end
@@ -7,25 +7,8 @@ module Wallaby
7
7
  # NOTE: Rails reload! will hit here
8
8
  # @see https://rmosolgo.github.io/ruby/rails/2017/04/12/watching-files-during-rails-development.html
9
9
  config.to_prepare do
10
- Map.clear
11
- Preloader.clear
10
+ Map.clear if Rails.env.development? || Rails.configuration.eager_load
12
11
  end
13
12
  end
14
-
15
- config.before_eager_load do
16
- Logger.debug 'Preload all model files before everything else.', sourcing: false
17
- Preloader.require_models
18
- end
19
-
20
- config.after_initialize do
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
29
- end
30
13
  end
31
14
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wallaby
4
+ # Guess the associated class for give class
5
+ class Guesser
6
+ SUFFIX = /(Controller|Decorator|Servicer|Authorizer|Paginator)$/.freeze # :no_doc:
7
+
8
+ class << self
9
+ # Find out the first demodulized class constant for the give class name.
10
+ # For example, if given class name is **Admin::Order::ItemsController**,
11
+ # then it will try to constantize the following demodulized class names
12
+ # and return the first one that is successfully constantized:
13
+ #
14
+ # - Admin::Order::Item
15
+ # - Order::Item
16
+ # - Item
17
+ # @param class_name [String]
18
+ # @param options [Hash]
19
+ # @return [Class] found associated class
20
+ # @return [nil] if not found
21
+ def class_for(class_name, options = {}, &block)
22
+ suffix = options[:suffix] || EMPTY_STRING
23
+ replacement = options[:replacement] || SUFFIX
24
+ denamespace = options.key?(:denamespace) ? options[:denamespace] : true
25
+ base_name = class_name.gsub(replacement, EMPTY_STRING).singularize << suffix
26
+ possible_class_from(base_name, denamespace: denamespace, &block)
27
+ end
28
+
29
+ def possible_class_from(class_name, denamespace: false)
30
+ target = nil
31
+ parts = denamespace ? class_name.split(COLONS) : [class_name]
32
+ parts.each_with_index.find do |_, index|
33
+ klass = Classifier.to_class(parts[index..].join(COLONS))
34
+ next unless klass
35
+ # additional checking, the given block should return true to continue
36
+ next if block_given? && !yield(klass)
37
+
38
+ target = klass
39
+ end
40
+
41
+ target
42
+ end
43
+ end
44
+ end
45
+ end
@@ -4,31 +4,53 @@ module Wallaby
4
4
  # Custom logger
5
5
  module Logger
6
6
  class << self
7
- %i(unknown fatal error warn info debug deprecated).each do |method_id|
7
+ %i[unknown fatal error warn info debug].each do |method_id|
8
8
  define_method method_id do |message, replacements = {}|
9
- sourcing = replacements.delete :sourcing # sourcing can be set to false
9
+ sourcing = replacements.delete(:sourcing) # sourcing can be set to false
10
10
  heading = replacements.delete(:heading) || 'WALLABY '
11
- new_message, from = normalize message, sourcing != false && Array(caller[sourcing || 0]) || nil
12
- Rails.logger.public_send(
13
- method_id == :deprecated ? :warn : method_id,
11
+ new_message, from = normalize(
12
+ message, (sourcing != false && Array.wrap(caller[sourcing || 0])) || nil
13
+ )
14
+ Wallaby.configuration.logger.try(
15
+ method_id,
14
16
  "#{heading}#{method_id.to_s.upcase}: #{format new_message, replacements}#{from}"
15
17
  )
16
18
  nil
17
19
  end
18
20
  end
19
21
 
22
+ # @param key [Symbol,String]
23
+ # @param message_or_config [String, false]
24
+ # @param replacements [Hash]
25
+ # @example to disable a particular hint message:
26
+ # Wallaby::Logger.hint(:customize_controller, false) if Wallaby::Logger.debug?
27
+ def hint(key, message_or_config, replacements = {})
28
+ @hint ||= {}
29
+ return @hint[key] = false if message_or_config == false
30
+ return if @hint[key] == false || !message_or_config.is_a?(String)
31
+
32
+ new_message = <<~MESSAGE
33
+ #{message_or_config}
34
+ This kind of debug message can be disabled in `config/initializers/wallaby.rb`:
35
+
36
+ Wallaby::Logger.hint(#{key.inspect}, false) if Wallaby::Logger.debug?
37
+ MESSAGE
38
+ debug(new_message, replacements.merge(sourcing: false))
39
+ end
40
+
20
41
  protected
21
42
 
22
- # @param message [Object]
43
+ # @param message [String,StandardError,Object]
44
+ # @param sources [Array<String>] array of files
23
45
  def normalize(message, sources)
24
- case message
25
- when String
26
- [message, sources && "\nfrom #{sources.join(" \n")}"]
27
- when StandardError
28
- [message.message, sources && "\n#{message.backtrace.join("\n")}"]
29
- else
30
- [message.inspect, sources && "\nfrom #{sources.join(" \n")}"]
46
+ if message.is_a?(StandardError)
47
+ return [
48
+ message.message,
49
+ sources && "\n#{message.backtrace.join("\n")}"
50
+ ]
31
51
  end
52
+
53
+ [message.to_s, sources && "\nfrom #{sources.join(" \n")}"]
32
54
  end
33
55
  end
34
56
  end
data/lib/wallaby/map.rb CHANGED
@@ -10,24 +10,23 @@ module Wallaby
10
10
  attr_writer :modes
11
11
 
12
12
  # @!attribute [r] modes
13
- # @return [Array<String>] all {Wallaby::Mode}s
13
+ # @return [Array<String>] all {Mode}s
14
14
  def modes
15
15
  @modes ||= ClassArray.new Mode.descendants
16
16
  end
17
17
 
18
- # @return [Wallaby::ClassHash] { Model Class => {Wallaby::Mode} }
18
+ # @return [ClassHash] { Model Class => {Mode} }
19
19
  def mode_map
20
20
  @mode_map ||= begin
21
- # NOTE: this is the point where all files should be required
22
- Preloader.require_all
21
+ # NOTE: this is the point where all model files should be required
22
+ Preloader.require_models
23
23
  ModeMapper.execute(modes).freeze
24
24
  end
25
25
  end
26
26
 
27
- # TODO: remove this method
28
- # @return [Array] [ model classes ]
27
+ # @deprecated
29
28
  def model_classes
30
- ModelClassCollector.new(configuration, mode_map.keys).collect
29
+ Deprecator.alert method(__callee__), from: '0.3.0'
31
30
  end
32
31
 
33
32
  # { model => resources name }
@@ -38,7 +37,7 @@ module Wallaby
38
37
  # @return [String] resources name
39
38
  def resources_name_map(model_class, value = nil)
40
39
  @resources_name_map ||= ClassHash.new
41
- @resources_name_map[model_class] ||= value || ModelUtils.to_resources_name(model_class)
40
+ @resources_name_map[model_class] ||= value || Inflector.to_resources_name(model_class)
42
41
  end
43
42
 
44
43
  # { resources name => model }
@@ -48,67 +47,21 @@ module Wallaby
48
47
  # @return [Class]
49
48
  def model_class_map(resources_name, value = nil)
50
49
  @model_class_map ||= ClassHash.new
51
- @model_class_map[resources_name] ||= value || ModelUtils.to_model_class(resources_name)
50
+ @model_class_map[resources_name] ||= value || Classifier.to_class(Inflector.to_model_name(resources_name))
52
51
  end
53
52
  end
54
53
 
55
54
  class << self
56
- # Look up which controller to use for a given model class
57
- # @param model_class [Class]
58
- # @param application_controller [Class, nil]
59
- # @return [Class] controller class, default to `mapping.resources_controller`
60
- def controller_map(model_class, application_controller = nil)
61
- application_controller ||= mapping.resources_controller
62
- map_of :@controller_map, model_class, application_controller
63
- end
64
-
65
- # Look up which resource decorator to use for a given model class
66
- # @param model_class [Class]
67
- # @param application_decorator [Class, nil]
68
- # @return [Class] resource decorator class, default to `mapping.resource_decorator`
69
- def resource_decorator_map(model_class, application_decorator = nil)
70
- application_decorator ||= mapping.resource_decorator
71
- map_of :@resource_decorator_map, model_class, application_decorator
72
- end
73
-
74
55
  # { model => model decorator }
75
56
  # @param model_class [Class]
76
- # @param application_decorator [Class, nil]
77
- # @return [Wallaby::ModelDecorator] model decorator instance
78
- def model_decorator_map(model_class, application_decorator = nil)
79
- application_decorator ||= mapping.resource_decorator
57
+ # @param application_decorator [Class]
58
+ # @return [ModelDecorator] model decorator instance
59
+ def model_decorator_map(model_class, application_decorator)
80
60
  @model_decorator_map ||= ClassHash.new
81
61
  @model_decorator_map[application_decorator] ||= ClassHash.new
82
62
  @model_decorator_map[application_decorator][model_class] ||=
83
63
  mode_map[model_class].try(:model_decorator).try :new, model_class
84
64
  end
85
-
86
- # Look up which model servicer to use for a given model class
87
- # @param model_class [Class]
88
- # @param application_servicer [Class, nil]
89
- # @return [Class] model servicer class, default to `mapping.model_servicer`
90
- def servicer_map(model_class, application_servicer = nil)
91
- application_servicer ||= mapping.model_servicer
92
- map_of :@servicer_map, model_class, application_servicer
93
- end
94
-
95
- # Look up which paginator to use for a given model class
96
- # @param model_class [Class]
97
- # @param application_paginator [Class, nil]
98
- # @return [Class] resource paginator class, default to `mapping.model_paginator`
99
- def paginator_map(model_class, application_paginator = nil)
100
- application_paginator ||= mapping.model_paginator
101
- map_of :@paginator_map, model_class, application_paginator
102
- end
103
-
104
- # Look up which authorizer to use for a given model class
105
- # @param model_class [Class]
106
- # @param application_authorizer [Class, nil]
107
- # @return [Class] model authorizer class, default to `mapping.model_authorizer`
108
- def authorizer_map(model_class, application_authorizer = nil)
109
- application_authorizer ||= mapping.model_authorizer
110
- map_of :@authorizer_map, model_class, application_authorizer
111
- end
112
65
  end
113
66
 
114
67
  class << self
@@ -142,36 +95,6 @@ module Wallaby
142
95
  def clear
143
96
  instance_variables.each { |name| instance_variable_set name, nil }
144
97
  end
145
-
146
- private
147
-
148
- # shorthand method
149
- def configuration
150
- ::Wallaby.configuration
151
- end
152
-
153
- # shorthand method
154
- def mapping
155
- configuration.mapping
156
- end
157
-
158
- # Set up the hash map for given variable name
159
- # @param variable_name [Symbol] instance variable name e.g. :@decorator_map
160
- # @param model_class [Class]
161
- # @param application_class [Class]
162
- # @return [Class]
163
- def map_of(variable_name, model_class, application_class)
164
- return unless model_class
165
-
166
- unless mode_map[model_class]
167
- Logger.warn Locale.t('map.missing_mode_for_model_class', model: model_class.name), sourcing: 2..5
168
- return
169
- end
170
- instance_variable_set(variable_name, instance_variable_get(variable_name) || ClassHash.new)
171
- map = instance_variable_get variable_name
172
- map[application_class] ||= ModelClassMapper.map application_class.descendants
173
- map[application_class][model_class] ||= application_class
174
- end
175
98
  end
176
99
  end
177
100
  end
@@ -3,7 +3,7 @@
3
3
  module Wallaby
4
4
  # Preload files for eager load paths.
5
5
  #
6
- # As Wallaby is built upon the {Wallaby::Map} which will not be completed
6
+ # As Wallaby is built upon the {Map} which will not be completed
7
7
  # until all models and decorators/controllers/servicers/authorizers/paginators
8
8
  # are loaded. Therefore, when Rails app is initialized,
9
9
  # all files under eager load paths (mostly `app/*` folders),
@@ -12,35 +12,16 @@ module Wallaby
12
12
  include ActiveModel::Model
13
13
 
14
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
28
-
29
- # Require models under {Wallaby::Configuration#model_paths}
15
+ # Require models under {Configuration#model_paths}
30
16
  # @see #model_file_paths
31
17
  def require_models
32
- new.model_file_paths.each(&method(:require_dependency))
18
+ new.model_file_paths.each { |path| require_dependency(path) } # rubocop:disable Rails/RequireDependency, Lint/RedundantCopDisableDirective
33
19
  end
34
20
  end
35
21
 
36
- # @return [Array<String>] all files under **Rails.configuration.eager_load_paths**
37
- def all_file_paths
38
- sort(all_eager_load_file_paths)
39
- end
40
-
41
- # @return [Array<String>] model files under {Wallaby::Configuration#model_paths}
22
+ # @return [Array<String>] model files under {Configuration#model_paths}
42
23
  def model_file_paths
43
- sort(all_eager_load_file_paths).select(&method(:indexed))
24
+ sort(all_eager_load_file_paths).select { |path| indexed(path) }
44
25
  end
45
26
 
46
27
  # @!attribute [w] eager_load_paths
@@ -52,7 +33,6 @@ module Wallaby
52
33
  @eager_load_paths ||=
53
34
  Rails.configuration.paths['app'].expanded
54
35
  .concat(Rails.configuration.eager_load_paths)
55
- .uniq
56
36
  end
57
37
 
58
38
  # @!attribute [w] model_paths
@@ -71,7 +51,7 @@ module Wallaby
71
51
  end
72
52
 
73
53
  # All files need to be sorted in the following orders:
74
- # 1. {Wallaby::Configuration#model_paths} order
54
+ # 1. {Configuration#model_paths} order
75
55
  # 2. Alphabet order
76
56
  def sort(file_paths)
77
57
  file_paths.sort { |p1, p2| conditions_for(p1) <=> conditions_for(p2) }
@@ -82,9 +62,9 @@ module Wallaby
82
62
  [indexed(path) || model_paths.length, path]
83
63
  end
84
64
 
85
- # Check if the path is in the {Wallaby::Configuration#model_paths}
65
+ # Check if the path is in the {Configuration#model_paths}
86
66
  def indexed(path)
87
- model_paths.index(&path.method(:include?))
67
+ model_paths.index { |p| path.include?(p) }
88
68
  end
89
69
  end
90
70
  end