wallaby-core 0.2.11 → 0.3.0.beta1

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 +24 -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 +72 -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 +2 -2
  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 +13 -80
  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 +7 -2
  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 +4 -4
  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 +2 -19
  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 +9 -31
  132. metadata +120 -15
  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
@@ -4,16 +4,9 @@ module Wallaby
4
4
  # Utils for module and class
5
5
  module ModuleUtils
6
6
  class << self
7
- # A helper method to check if subject responds to given method and to return the result if so
8
- # @param subject [Object]
9
- # @param method_id [String, Symbol]
10
- # @param args [Array] a list of arguments
11
- # @return [Object] result from executing given method on subject
12
- # @return [nil] if subject doesn't respond to given method
13
- def try_to(subject, method_id, *args, &block)
14
- return if method_id.blank?
15
-
16
- subject.respond_to?(method_id) && subject.public_send(method_id, *args, &block) || nil
7
+ # @deprecated
8
+ def try_to(_subject, _method_id, *_args)
9
+ Deprecator.alert method(__callee__), from: '0.3.0'
17
10
  end
18
11
 
19
12
  # Check whether a class is anonymous or not
@@ -1,24 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wallaby
4
- # Utils
5
- module Utils
6
- # @see http://stackoverflow.com/a/8710663/1326499
4
+ module Utils # :nodoc:
7
5
  # @param object [Object]
8
- # @return [Object] a clone object
6
+ # @return [Object] a cloned object
9
7
  def self.clone(object)
10
- # NOTE: Neither marshal/deep_dup/dup are able to achieve real and correct deep copy,
11
- # so here we need a custom solution below:
8
+ # NOTE: Neither marshal/deep_dup/dup is able to make a correct deep copy,
9
+ # therefore, this is our solution:
12
10
  case object
13
11
  when Hash
14
- object
15
- .each_with_object(object.class.new) { |(key, value), hash| hash[key] = clone(value) }
16
- .tap { |hash| hash.default = object.default }
12
+ HashCloner.execute(object)
17
13
  when Array
18
14
  object.each_with_object(object.class.new) { |value, array| array << clone(value) }
19
15
  when Class
20
- # NOTE: `Class.dup` will turn the duplicate class into anonymous class
21
- # therefore, we just return the Class itself here
16
+ # NOTE: `Class.dup` turns the origin Class object into an anonymous clone.
17
+ # therefore, the Class object itself should be returned instead
22
18
  object
23
19
  else
24
20
  object.dup
@@ -28,10 +24,21 @@ module Wallaby
28
24
  # @param object [Object, nil]
29
25
  # @return [String] inspection string for the given object
30
26
  def self.inspect(object)
31
- return 'nil' unless object
32
- return object.name if object.is_a? Class
27
+ return 'nil' if object.nil?
28
+ return "#{object.class}##{object.try(:id)}" if object.is_a?(::ActiveRecord::Base)
29
+
30
+ object.inspect
31
+ end
33
32
 
34
- "#{object.class}##{object.id}"
33
+ # Service object to clone Hash
34
+ class HashCloner
35
+ def self.execute(object)
36
+ # NOTE: `default`/`default_proc` should be cloned as well
37
+ default_method = object.default_proc ? :default_proc : :default
38
+ object
39
+ .each_with_object(object.class.new) { |(key, value), hash| hash[key] = Utils.clone(value) }
40
+ .tap { |hash| hash.try("#{default_method}=", object.try(default_method)) }
41
+ end
35
42
  end
36
43
  end
37
44
  end
@@ -6,11 +6,11 @@ module Wallaby
6
6
  include Classifier
7
7
 
8
8
  # @param [Array] array
9
- def initialize(array = [])
10
- @internal = array || []
9
+ def initialize(*array)
10
+ @internal = (array || []).flatten
11
11
  return if @internal.blank?
12
12
 
13
- @internal.map!(&method(:to_class_name)).compact!
13
+ @internal.map! { |klass| class_name_of(klass) }.compact!
14
14
  end
15
15
 
16
16
  # @!attribute [r] internal
@@ -20,13 +20,13 @@ module Wallaby
20
20
  # @!attribute [r] origin
21
21
  # @return [Array] The original array.
22
22
  def origin
23
- # NOTE: DO NOT cache it by using instance variable!
24
- @internal.map(&method(:to_class)).compact
23
+ # NOTE: DO NOT cache it using instance variable!
24
+ @internal.map { |klass| to_class(klass) }.compact
25
25
  end
26
26
 
27
27
  # Save the value to the {#internal} array at the given index, and convert the Class value to String
28
28
  def []=(index, value)
29
- @internal[index] = to_class_name value
29
+ @internal[index] = class_name_of value
30
30
  end
31
31
 
32
32
  # Return the value for the given index
@@ -35,18 +35,19 @@ module Wallaby
35
35
  end
36
36
 
37
37
  # @param other [Array]
38
- # @return [Wallaby::ClassArray] new Class array
38
+ # @return [ClassArray] new Class array
39
39
  def concat(other)
40
40
  self.class.new origin.concat(other.try(:origin) || other)
41
41
  end
42
42
 
43
- # @param other [Array]
44
- # @return [Wallaby::ClassArray] new Class array
45
- def -(other)
46
- self.class.new origin - (other.try(:origin) || other)
43
+ # @param item [Class, String]
44
+ # @return [ClassArray] self
45
+ def <<(item)
46
+ @internal << class_name_of(item)
47
+ self
47
48
  end
48
49
 
49
- # @return [Wallaby::ClassArray] self
50
+ # @return [ClassArray] self
50
51
  def each(&block)
51
52
  origin.each(&block)
52
53
  self
@@ -56,6 +57,10 @@ module Wallaby
56
57
  # Compare #{origin} with other.
57
58
  delegate :==, to: :origin
58
59
 
60
+ # @!method to_a
61
+ # Get the array of #{origin}.
62
+ delegate :to_a, to: :origin
63
+
59
64
  # @!method blank?
60
65
  delegate :blank?, to: :internal
61
66
 
@@ -66,7 +71,7 @@ module Wallaby
66
71
  delegate :to_sentence, to: :origin
67
72
 
68
73
  # Ensure to freeze the {#internal}
69
- # @return [Wallaby::ClassArray] self
74
+ # @return [ClassArray] self
70
75
  def freeze
71
76
  @internal.freeze
72
77
  super
@@ -4,7 +4,7 @@ module Wallaby
4
4
  # This is a constant-safe hash that stores Class key/value as String
5
5
  # and returns value as Class if it was a Class.
6
6
  #
7
- # It can be used for global methods (e.g. {Wallaby::Map.mode_map}) which cache the computed result,
7
+ # It can be used for global methods (e.g. {Map.mode_map}) which cache the computed result,
8
8
  # so that when Rails reloads, it won't complain that old Class constants still exist in
9
9
  # ObjectSpace (see https://github.com/wallaby-rails/wallaby/issues/181).
10
10
  #
@@ -22,8 +22,8 @@ module Wallaby
22
22
  def initialize(hash = {})
23
23
  @internal =
24
24
  (hash || {})
25
- .transform_keys(&method(:to_class_name))
26
- .transform_values(&method(:to_class_name))
25
+ .transform_keys { |klass| class_name_of(klass) }
26
+ .transform_values { |klass| class_name_of(klass) }
27
27
  end
28
28
 
29
29
  # @!attribute [r] origin
@@ -31,11 +31,15 @@ module Wallaby
31
31
  def origin
32
32
  # NOTE: DO NOT cache it by using instance variable!
33
33
  @internal
34
- .transform_keys(&method(:to_class))
35
- .transform_values(&method(:to_class))
34
+ .transform_keys { |klass| to_class(klass) }
35
+ .transform_values { |klass| to_class(klass) }
36
36
  .reject { |k, v| k.nil? || v.nil? }
37
37
  end
38
38
 
39
+ # @!method key?
40
+ # Return if {#origin} has the given key.
41
+ delegate :key?, to: :origin
42
+
39
43
  # @!method keys
40
44
  # Return the keys of {#origin}.
41
45
  delegate :keys, to: :origin
@@ -50,27 +54,27 @@ module Wallaby
50
54
 
51
55
  # Save the key/value to the {#internal} hash, and convert the Class key/value to String
52
56
  def []=(key, value)
53
- @internal[to_class_name(key)] = to_class_name(value)
57
+ @internal[class_name_of(key)] = class_name_of(value)
54
58
  end
55
59
 
56
60
  # Return the value for the given key, and convert the value back to Class if it was a Class
57
61
  def [](key)
58
- to_class @internal[to_class_name(key)]
62
+ to_class @internal[class_name_of(key)]
59
63
  end
60
64
 
61
65
  # @param other [Hash]
62
- # @return [Wallaby::ClassHash] new Class hash
66
+ # @return [ClassHash] new Class hash
63
67
  def merge(other)
64
68
  self.class.new origin.merge(other.try(:origin) || other)
65
69
  end
66
70
 
67
- # @return [Wallaby::ClassHash] new Class hash
71
+ # @return [ClassHash] new Class hash
68
72
  def select(&block)
69
73
  self.class.new origin.select(&block)
70
74
  end
71
75
 
72
76
  # Ensure to freeze the {#internal}
73
- # @return [Wallaby::ClassHash] self
77
+ # @return [ClassHash] self
74
78
  def freeze
75
79
  @internal.freeze
76
80
  super
@@ -79,16 +83,14 @@ module Wallaby
79
83
  protected
80
84
 
81
85
  # Convert to Class name
82
- def to_class_name(klass)
86
+ def class_name_of(klass)
83
87
  klass.is_a?(Class) ? [klass.name, true] : [klass, false]
84
88
  end
85
89
 
86
90
  # Convert to Class
87
91
  def to_class(pair)
88
92
  val, is_class = pair
89
- is_class ? val.constantize : val
90
- rescue NameError
91
- Logger.error "`#{val}` is not a valid Class name."
93
+ is_class ? Classifier.to_class(val) : val
92
94
  end
93
95
  end
94
96
  end
@@ -3,11 +3,13 @@
3
3
  module Wallaby
4
4
  # Concern to handle the conversion between Class and String
5
5
  module Classifier
6
+ extend self
7
+
6
8
  # Convert Class to String. If not Class, unchanged.
7
9
  # @param klass [Object]
8
10
  # @return [String] if klass is a Class
9
11
  # @return [Object] if klass is not a Class
10
- def to_class_name(klass)
12
+ def class_name_of(klass)
11
13
  klass.try(:name) || klass || nil
12
14
  end
13
15
 
@@ -23,7 +25,7 @@ module Wallaby
23
25
  # This is Rails, use constantize
24
26
  name.constantize
25
27
  rescue NameError
26
- Logger.error "`#{name}` is not a valid Class name."
28
+ yield(name) if block_given?
27
29
  end
28
30
  end
29
31
  end
@@ -5,7 +5,9 @@ module Wallaby
5
5
  # Features global configuration
6
6
  class Features
7
7
  # @!attribute [w] turbolinks_enabled
8
- attr_writer :turbolinks_enabled
8
+ def turbolinks_enabled=(_turbolinks_enabled)
9
+ Deprecator.alert 'config.features.turbolinks_enabled=', from: '0.3.0'
10
+ end
9
11
 
10
12
  # @!attribute [r] turbolinks_enabled
11
13
  # To globally configure whether to use turbolinks or not.
@@ -17,7 +19,11 @@ module Wallaby
17
19
  # end
18
20
  # @return [Boolean] a feture flag of turbolinks, default to false.
19
21
  def turbolinks_enabled
20
- @turbolinks_enabled ||= false
22
+ Deprecator.alert method(__callee__), from: '0.3.0', alternative: <<~INSTRUCTION
23
+ If Turbolinks is included, it will be used by Wallaby. If you want to disable it,
24
+ you can either take `turbolinks` gem out from your Gemfile
25
+ or override the `frontend` partial by taking it out.
26
+ INSTRUCTION
21
27
  end
22
28
  end
23
29
  end
@@ -2,144 +2,98 @@
2
2
 
3
3
  module Wallaby
4
4
  class Configuration
5
- # Configuration used in {Wallaby::Map}
6
- # @since wallaby-5.1.6
5
+ # @deprecated
7
6
  class Mapping
8
7
  include Classifier
9
8
 
10
- # @!attribute [w] resources_controller
11
- def resources_controller=(resources_controller)
12
- @resources_controller = to_class_name resources_controller
9
+ # @deprecated
10
+ def resources_controller=(_resources_controller)
11
+ Deprecator.alert 'config.mapping.resources_controller=', from: '0.3.0', alternative: <<~INSTRUCTION
12
+ Please set #resources_controller= from the config instead, for example:
13
+
14
+ Wallaby.config do |config|
15
+ config.resources_controller = ::GlobalResourcesController
16
+ end
17
+ INSTRUCTION
13
18
  end
14
19
 
15
- # @!attribute [r] resources_controller
16
- # To globally configure the resources controller.
17
- #
18
- # If no configuration is given, Wallaby will look up from the following controller classes
19
- # and use the first available one:
20
- #
21
- # - ::Admin::ApplicationController (only when it inherits from {Wallaby::ResourcesController})
22
- # - {Wallaby::ResourcesController}
23
- # @example To update the resources controller to `GlobalResourcesController` in `config/initializers/wallaby.rb`
24
- # Wallaby.config do |config|
25
- # config.mapping.resources_controller = ::GlobalResourcesController
26
- # end
27
- # @return [Class] resources controller class
28
- # @since wallaby-5.1.6
20
+ # @deprecated
29
21
  def resources_controller
30
- @resources_controller ||=
31
- defined?(::Admin::ApplicationController) \
32
- && ::Admin::ApplicationController < ::Wallaby::ResourcesController \
33
- && 'Admin::ApplicationController'
34
- to_class @resources_controller ||= 'Wallaby::ResourcesController'
22
+ Deprecator.alert 'config.mapping.resources_controller', from: '0.3.0', alternative: <<~INSTRUCTION
23
+ Please use config.resources_controller instead.
24
+ INSTRUCTION
35
25
  end
36
26
 
37
- # @!attribute [w] resource_decorator
38
- def resource_decorator=(resource_decorator)
39
- @resource_decorator = to_class_name resource_decorator
27
+ # @deprecated
28
+ def resource_decorator=(_resource_decorator)
29
+ Deprecator.alert 'config.mapping.resource_decorator=', from: '0.3.0', alternative: <<~INSTRUCTION
30
+ Please set .application_decorator= from the controller instead, for example:
31
+
32
+ class Admin::ApplicationController < Wallaby::ResourcesController
33
+ self.application_decorator = ::GlobalModelDecorator
34
+ end
35
+ INSTRUCTION
40
36
  end
41
37
 
42
- # @!attribute [r] resource_decorator
43
- # To globally configure the resource decorator.
44
- #
45
- # If no configuration is given, Wallaby will look up from the following decorator classes
46
- # and use the first available one:
47
- #
48
- # - ::Admin::ApplicationDecorator (only when it inherits from {Wallaby::ResourceDecorator})
49
- # - {Wallaby::ResourceDecorator}
50
- # @example To update the resource decorator to `GlobalResourceDecorator` in `config/initializers/wallaby.rb`
51
- # Wallaby.config do |config|
52
- # config.mapping.resource_decorator = ::GlobalResourceDecorator
53
- # end
54
- # @return [Class] resource decorator class
55
- # @since wallaby-5.1.6
38
+ # @deprecated
56
39
  def resource_decorator
57
- @resource_decorator ||=
58
- defined?(::Admin::ApplicationDecorator) \
59
- && ::Admin::ApplicationDecorator < ::Wallaby::ResourceDecorator \
60
- && 'Admin::ApplicationDecorator'
61
- to_class @resource_decorator ||= 'Wallaby::ResourceDecorator'
40
+ Deprecator.alert 'config.mapping.resource_decorator', from: '0.3.0', alternative: <<~INSTRUCTION
41
+ Please use controller_class.application_decorator.
42
+ INSTRUCTION
62
43
  end
63
44
 
64
- # @!attribute [w] model_servicer
65
- def model_servicer=(model_servicer)
66
- @model_servicer = to_class_name model_servicer
45
+ # @deprecated
46
+ def model_servicer=(_model_servicer)
47
+ Deprecator.alert 'config.mapping.model_servicer=', from: '0.3.0', alternative: <<~INSTRUCTION
48
+ Please set .application_servicer= from the controller instead, for example:
49
+
50
+ class Admin::ApplicationController < Wallaby::ResourcesController
51
+ self.application_servicer = ::GlobalModelServicer
52
+ end
53
+ INSTRUCTION
67
54
  end
68
55
 
69
- # @!attribute [r] model_servicer
70
- # To globally configure the model servicer.
71
- #
72
- # If no configuration is given, Wallaby will look up from the following servicer classes
73
- # and use the first available one:
74
- #
75
- # - ::Admin::ApplicationServicer (only when it inherits from {Wallaby::ModelServicer})
76
- # - {Wallaby::ModelServicer}
77
- # @example To update the model servicer to `GlobalModelServicer` in `config/initializers/wallaby.rb`
78
- # Wallaby.config do |config|
79
- # config.mapping.model_servicer = ::GlobalModelServicer
80
- # end
81
- # @return [Class] model servicer class
82
- # @since wallaby-5.1.6
56
+ # @deprecated
83
57
  def model_servicer
84
- @model_servicer ||=
85
- defined?(::Admin::ApplicationServicer) \
86
- && ::Admin::ApplicationServicer < ::Wallaby::ModelServicer \
87
- && 'Admin::ApplicationServicer'
88
- to_class @model_servicer ||= 'Wallaby::ModelServicer'
58
+ Deprecator.alert 'config.mapping.model_servicer', from: '0.3.0', alternative: <<~INSTRUCTION
59
+ Please use controller_class.application_servicer.
60
+ INSTRUCTION
89
61
  end
90
62
 
91
- # @!attribute [w] model_authorizer
92
- def model_authorizer=(model_authorizer)
93
- @model_authorizer = to_class_name model_authorizer
63
+ # @deprecated
64
+ def model_authorizer=(_model_authorizer)
65
+ Deprecator.alert 'config.mapping.model_authorizer=', from: '0.3.0', alternative: <<~INSTRUCTION
66
+ Please set .application_authorizer= from the controller instead, for example:
67
+
68
+ class Admin::ApplicationController < Wallaby::ResourcesController
69
+ self.application_authorizer = ::GlobalModelAuthorizer
70
+ end
71
+ INSTRUCTION
94
72
  end
95
73
 
96
- # @!attribute [r] model_authorizer
97
- # To globally configure the model authorizer.
98
- #
99
- # If no configuration is given, Wallaby will look up from the following authorizer classes
100
- # and use the first available one:
101
- #
102
- # - ::Admin::ApplicationAuthorizer (only when it inherits from {Wallaby::ModelAuthorizer})
103
- # - {Wallaby::ModelAuthorizer}
104
- # @example To update the model authorizer to `GlobalModelAuthorizer` in `config/initializers/wallaby.rb`
105
- # Wallaby.config do |config|
106
- # config.mapping.model_authorizer = ::GlobalModelAuthorizer
107
- # end
108
- # @return [Class] model authorizer class
109
- # @since wallaby-5.2.0
74
+ # @deprecated
110
75
  def model_authorizer
111
- @model_authorizer ||=
112
- defined?(::Admin::ApplicationAuthorizer) \
113
- && ::Admin::ApplicationAuthorizer < ::Wallaby::ModelAuthorizer \
114
- && 'Admin::ApplicationAuthorizer'
115
- to_class @model_authorizer ||= 'Wallaby::ModelAuthorizer'
76
+ Deprecator.alert 'config.mapping.model_authorizer', from: '0.3.0', alternative: <<~INSTRUCTION
77
+ Please use controller_class.application_authorizer.
78
+ INSTRUCTION
116
79
  end
117
80
 
118
- # @!attribute [w] model_paginator
119
- def model_paginator=(model_paginator)
120
- @model_paginator = to_class_name model_paginator
81
+ # @deprecated
82
+ def model_paginator=(_model_paginator)
83
+ Deprecator.alert 'config.mapping.model_paginator=', from: '0.3.0', alternative: <<~INSTRUCTION
84
+ Please set .application_paginator= from the controller instead, for example:
85
+
86
+ class Admin::ApplicationController < Wallaby::ResourcesController
87
+ self.application_paginator = ::GlobalModelPaginator
88
+ end
89
+ INSTRUCTION
121
90
  end
122
91
 
123
- # @!attribute [r] model_paginator
124
- # To globally configure the resource paginator.
125
- #
126
- # If no configuration is given, Wallaby will look up from the following paginator classes
127
- # and use the first available one:
128
- #
129
- # - ::Admin::ApplicationPaginator (only when it inherits from {Wallaby::ModelPaginator})
130
- # - {Wallaby::ModelPaginator}
131
- # @example To update the resource paginator to `GlobalModelPaginator` in `config/initializers/wallaby.rb`
132
- # Wallaby.config do |config|
133
- # config.mapping.model_paginator = ::GlobalModelPaginator
134
- # end
135
- # @return [Class] resource paginator class
136
- # @since wallaby-5.2.0
92
+ # @deprecated
137
93
  def model_paginator
138
- @model_paginator ||=
139
- defined?(::Admin::ApplicationPaginator) \
140
- && ::Admin::ApplicationPaginator < ::Wallaby::ModelPaginator \
141
- && 'Admin::ApplicationPaginator'
142
- to_class @model_paginator ||= 'Wallaby::ModelPaginator'
94
+ Deprecator.alert 'config.mapping.model_paginator', from: '0.3.0', alternative: <<~INSTRUCTION
95
+ Please use controller_class.application_paginator.
96
+ INSTRUCTION
143
97
  end
144
98
  end
145
99
  end
@@ -2,21 +2,24 @@
2
2
 
3
3
  module Wallaby
4
4
  class Configuration
5
- # Metadata configuration
5
+ # @deprecated
6
6
  class Metadata
7
- # @!attribute [w] max
8
- attr_writer :max
7
+ # @deprecated
8
+ def max=(_max)
9
+ Deprecator.alert 'config.metadata.max=', from: '0.3.0', alternative: <<~INSTRUCTION
10
+ Please set .max_text_length= from the controller instead, for example:
9
11
 
10
- # @!attribute [r] resources_controller
11
- # To globally configure max number of characters to truncate.
12
- # @example To update max number of characters to truncate to 50 in `config/initializers/wallaby.rb`
13
- # Wallaby.config do |config|
14
- # config.metadata.max = 50
15
- # end
16
- # @return [Integer] max number of characters to truncate, default to 20
17
- # @since wallaby-5.1.6
12
+ class Admin::ApplicationController < Wallaby::ResourcesController
13
+ self.max_text_length = 50
14
+ end
15
+ INSTRUCTION
16
+ end
17
+
18
+ # @deprecated
18
19
  def max
19
- @max ||= DEFAULT_MAX
20
+ Deprecator.alert 'config.metadata.max', from: '0.3.0', alternative: <<~INSTRUCTION
21
+ Please use controller_class.max_text_length instead.
22
+ INSTRUCTION
20
23
  end
21
24
  end
22
25
  end
@@ -2,40 +2,42 @@
2
2
 
3
3
  module Wallaby
4
4
  class Configuration
5
- # @deprecated will move this configuration to {Wallaby::ResourcesController} from 6.2
6
- # Models configuration to specify the model classes that Wallaby should handle.
5
+ # @deprecated
7
6
  class Models
8
- # @note If models are whitelisted, models exclusion will NOT be applied.
9
- # To globally configure what model classes that Wallaby should handle.
10
- # @example To whitelist the model classes in `config/initializers/wallaby.rb`
11
- # Wallaby.config do |config|
12
- # config.models = [Product, Order]
13
- # end
14
- # @param models [Array<Class, String>]
15
- def set(*models)
16
- @models = ClassArray.new(models.flatten)
7
+ # @deprecated
8
+ def set(*_models)
9
+ Deprecator.alert 'config.models.set', from: '0.3.0', alternative: <<~INSTRUCTION
10
+ Please set #models= from the controller instead, for example:
11
+
12
+ class Admin::ApplicationController < Wallaby::ResourcesController
13
+ self.models = User, 'Product'
14
+ end
15
+ INSTRUCTION
17
16
  end
18
17
 
19
- # @return [Array<Class>] the models configured
18
+ # @deprecated
20
19
  def presence
21
- @models ||= ClassArray.new # rubocop:disable Naming/MemoizedInstanceVariableName
20
+ Deprecator.alert 'config.models.presence', from: '0.3.0', alternative: <<~INSTRUCTION
21
+ Please use controller_class.models instead.
22
+ INSTRUCTION
22
23
  end
23
24
 
24
- # @note If models are whitelisted using {#set}, models exclusion will NOT be applied.
25
- # To globally configure what model classes to exclude.
26
- # @example To exclude models in `config/initializers/wallaby.rb`
27
- # Wallaby.config do |config|
28
- # config.models.exclude Product, Order
29
- # end
30
- # @param models [Array<Class, String>]
31
- def exclude(*models)
32
- @excludes = ClassArray.new(models.flatten)
25
+ # @deprecated
26
+ def exclude(*_models)
27
+ Deprecator.alert 'config.models.exclude', from: '0.3.0', alternative: <<~INSTRUCTION
28
+ Please set #models_to_exclude from the controller instead, for example:
29
+
30
+ class Admin::ApplicationController < Wallaby::ResourcesController
31
+ self.models_to_exclude User, 'Product'
32
+ end
33
+ INSTRUCTION
33
34
  end
34
35
 
35
- # @return [Array<Class>] the list of models to exclude.
36
- # By default, `ActiveRecord::SchemaMigration` is excluded.
36
+ # @deprecated
37
37
  def excludes
38
- @excludes ||= ClassArray.new ['ActiveRecord::SchemaMigration']
38
+ Deprecator.alert 'config.models.excludes', from: '0.3.0', alternative: <<~INSTRUCTION
39
+ Please use controller_class.models_to_exclude instead.
40
+ INSTRUCTION
39
41
  end
40
42
  end
41
43
  end
@@ -2,28 +2,24 @@
2
2
 
3
3
  module Wallaby
4
4
  class Configuration
5
- # Pagination configuration
5
+ # @deprecated
6
6
  class Pagination
7
- # @!attribute [w] page_size
8
- attr_writer :page_size
7
+ # @deprecated
8
+ def page_size=(_page_size)
9
+ Deprecator.alert 'config.pagination.page_size=', from: '0.3.0', alternative: <<~INSTRUCTION
10
+ Please set #page_size= from the controller instead, for example:
9
11
 
10
- # @!attribute [r] page_size
11
- # To globally configure the page size for pagination.
12
- #
13
- # Page size can be one of the following values:
14
- #
15
- # - 10
16
- # - 20
17
- # - 50
18
- # - 100
19
- # @see Wallaby::PERS
20
- # @example To update the page size in `config/initializers/wallaby.rb`
21
- # Wallaby.config do |config|
22
- # config.pagination.page_size = 50
23
- # end
24
- # @return [Integer] page size, default to 20
12
+ class Admin::ApplicationController < Wallaby::ResourcesController
13
+ self.page_size = 50
14
+ end
15
+ INSTRUCTION
16
+ end
17
+
18
+ # @deprecated
25
19
  def page_size
26
- @page_size ||= DEFAULT_PAGE_SIZE
20
+ Deprecator.alert 'config.pagination.page_size', from: '0.3.0', alternative: <<~INSTRUCTION
21
+ Please use controller_class.page_size instead.
22
+ INSTRUCTION
27
23
  end
28
24
  end
29
25
  end