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.
- checksums.yaml +4 -4
- data/app/controllers/wallaby/resources_controller.rb +20 -7
- data/app/security/ability.rb +1 -1
- data/config/routes.rb +21 -14
- data/lib/adaptors/wallaby/custom/default_provider.rb +1 -1
- data/lib/adaptors/wallaby/custom/model_decorator.rb +5 -17
- data/lib/adaptors/wallaby/custom/model_finder.rb +3 -3
- data/lib/adaptors/wallaby/custom/model_pagination_provider.rb +1 -1
- data/lib/adaptors/wallaby/custom/model_service_provider.rb +1 -1
- data/lib/authorizers/wallaby/cancancan_authorization_provider.rb +12 -5
- data/lib/authorizers/wallaby/default_authorization_provider.rb +10 -1
- data/lib/authorizers/wallaby/model_authorizer.rb +41 -16
- data/lib/authorizers/wallaby/pundit_authorization_provider.rb +22 -8
- data/lib/concerns/wallaby/application_concern.rb +41 -71
- data/lib/concerns/wallaby/authentication_concern.rb +29 -127
- data/lib/concerns/wallaby/authorizable.rb +14 -57
- data/lib/concerns/wallaby/baseable.rb +24 -57
- data/lib/concerns/wallaby/configurable.rb +416 -0
- data/lib/concerns/wallaby/decoratable.rb +24 -60
- data/lib/concerns/wallaby/engineable.rb +29 -46
- data/lib/concerns/wallaby/fieldable.rb +45 -56
- data/lib/concerns/wallaby/paginatable.rb +20 -51
- data/lib/concerns/wallaby/prefixable.rb +24 -4
- data/lib/concerns/wallaby/resourcable.rb +130 -72
- data/lib/concerns/wallaby/resources_concern.rb +205 -305
- data/lib/concerns/wallaby/servicable.rb +8 -48
- data/lib/concerns/wallaby/urlable.rb +69 -0
- data/lib/decorators/wallaby/resource_decorator.rb +72 -34
- data/lib/errors/wallaby/class_not_found.rb +1 -2
- data/lib/errors/wallaby/forbidden.rb +1 -2
- data/lib/errors/wallaby/general_error.rb +1 -1
- data/lib/errors/wallaby/invalid_error.rb +1 -2
- data/lib/errors/wallaby/method_removed.rb +5 -0
- data/lib/errors/wallaby/model_not_found.rb +1 -2
- data/lib/errors/wallaby/not_authenticated.rb +1 -2
- data/lib/errors/wallaby/not_found.rb +1 -2
- data/lib/errors/wallaby/not_implemented.rb +1 -2
- data/lib/errors/wallaby/resource_not_found.rb +1 -2
- data/lib/errors/wallaby/unprocessable_entity.rb +1 -2
- data/lib/fields/wallaby/all_fields.rb +63 -0
- data/lib/forms/wallaby/form_builder.rb +2 -2
- data/lib/generators/wallaby/engine/application_generator.rb +33 -0
- data/lib/generators/wallaby/engine/authorizer/USAGE +20 -0
- data/lib/generators/wallaby/engine/authorizer/authorizer_generator.rb +19 -0
- data/lib/generators/wallaby/engine/authorizer/templates/authorizer.rb.erb +35 -0
- data/lib/generators/wallaby/engine/controller/USAGE +20 -0
- data/lib/generators/wallaby/engine/controller/controller_generator.rb +23 -0
- data/lib/generators/wallaby/engine/controller/templates/controller.rb.erb +130 -0
- data/lib/generators/wallaby/engine/decorator/USAGE +20 -0
- data/lib/generators/wallaby/engine/decorator/decorator_generator.rb +19 -0
- data/lib/generators/wallaby/engine/decorator/templates/decorator.rb.erb +5 -0
- data/lib/generators/wallaby/engine/install/USAGE +19 -0
- data/lib/generators/wallaby/engine/install/install_generator.rb +91 -0
- data/lib/generators/wallaby/engine/install/templates/application_authorizer.rb.erb +37 -0
- data/lib/generators/wallaby/engine/install/templates/application_controller.rb.erb +173 -0
- data/lib/generators/wallaby/engine/install/templates/application_decorator.rb.erb +7 -0
- data/lib/generators/wallaby/engine/install/templates/application_paginator.rb.erb +27 -0
- data/lib/generators/wallaby/engine/install/templates/application_servicer.rb.erb +47 -0
- data/lib/generators/wallaby/engine/install/templates/initializer.rb.erb +16 -0
- data/lib/generators/wallaby/engine/paginator/USAGE +20 -0
- data/lib/generators/wallaby/engine/paginator/paginator_generator.rb +19 -0
- data/lib/generators/wallaby/engine/paginator/templates/paginator.rb.erb +25 -0
- data/lib/generators/wallaby/engine/servicer/USAGE +20 -0
- data/lib/generators/wallaby/engine/servicer/servicer_generator.rb +19 -0
- data/lib/generators/wallaby/engine/servicer/templates/servicer.rb.erb +45 -0
- data/lib/helpers/wallaby/application_helper.rb +10 -59
- data/lib/helpers/wallaby/base_helper.rb +11 -11
- data/lib/helpers/wallaby/configuration_helper.rb +36 -4
- data/lib/helpers/wallaby/form_helper.rb +1 -1
- data/lib/helpers/wallaby/index_helper.rb +19 -9
- data/lib/helpers/wallaby/links_helper.rb +13 -80
- data/lib/helpers/wallaby/resources_helper.rb +39 -7
- data/lib/helpers/wallaby/secure_helper.rb +20 -19
- data/lib/interfaces/wallaby/mode.rb +8 -8
- data/lib/interfaces/wallaby/model_authorization_provider.rb +23 -22
- data/lib/interfaces/wallaby/model_decorator.rb +36 -48
- data/lib/interfaces/wallaby/model_finder.rb +3 -3
- data/lib/interfaces/wallaby/model_pagination_provider.rb +2 -6
- data/lib/interfaces/wallaby/model_service_provider.rb +4 -4
- data/lib/paginators/wallaby/model_paginator.rb +1 -1
- data/lib/responders/wallaby/json_api_responder.rb +10 -5
- data/lib/responders/wallaby/resources_responder.rb +7 -2
- data/lib/routes/wallaby/engines/base_route.rb +78 -0
- data/lib/routes/wallaby/engines/custom_app_route.rb +92 -0
- data/lib/routes/wallaby/engines/engine_route.rb +77 -0
- data/lib/routes/wallaby/resources_router.rb +100 -45
- data/lib/servicers/wallaby/model_servicer.rb +13 -13
- data/lib/services/wallaby/authorizer_finder.rb +23 -0
- data/lib/services/wallaby/class_finder.rb +42 -0
- data/lib/services/wallaby/controller_finder.rb +29 -0
- data/lib/services/wallaby/decorator_finder.rb +34 -0
- data/lib/services/wallaby/default_models_excluder.rb +45 -0
- data/lib/services/wallaby/engine_name_finder.rb +14 -11
- data/lib/services/wallaby/engine_url_for.rb +82 -37
- data/lib/services/wallaby/fields_regulator.rb +34 -0
- data/lib/services/wallaby/map/mode_mapper.rb +4 -4
- data/lib/services/wallaby/map/model_class_mapper.rb +1 -1
- data/lib/services/wallaby/model_class_filter.rb +29 -0
- data/lib/services/wallaby/paginator_finder.rb +24 -0
- data/lib/services/wallaby/prefixes_builder.rb +49 -8
- data/lib/services/wallaby/servicer_finder.rb +31 -0
- data/lib/services/wallaby/sorting/hash_builder.rb +9 -0
- data/lib/services/wallaby/sorting/link_builder.rb +7 -10
- data/lib/services/wallaby/sorting/next_builder.rb +1 -12
- data/lib/services/wallaby/sorting/single_builder.rb +1 -1
- data/lib/support/action_dispatch/routing/mapper.rb +29 -4
- data/lib/utils/wallaby/field_utils.rb +9 -8
- data/lib/utils/wallaby/inflector.rb +94 -0
- data/lib/utils/wallaby/locale.rb +2 -2
- data/lib/utils/wallaby/module_utils.rb +3 -10
- data/lib/utils/wallaby/utils.rb +21 -14
- data/lib/wallaby/class_array.rb +18 -13
- data/lib/wallaby/class_hash.rb +16 -14
- data/lib/wallaby/classifier.rb +4 -2
- data/lib/wallaby/configuration/features.rb +8 -2
- data/lib/wallaby/configuration/mapping.rb +66 -112
- data/lib/wallaby/configuration/metadata.rb +15 -12
- data/lib/wallaby/configuration/models.rb +27 -25
- data/lib/wallaby/configuration/pagination.rb +15 -19
- data/lib/wallaby/configuration/security.rb +88 -80
- data/lib/wallaby/configuration/sorting.rb +15 -17
- data/lib/wallaby/configuration.rb +58 -23
- data/lib/wallaby/constants.rb +21 -13
- data/lib/wallaby/core/version.rb +1 -1
- data/lib/wallaby/core.rb +34 -10
- data/lib/wallaby/deprecator.rb +81 -0
- data/lib/wallaby/engine.rb +2 -19
- data/lib/wallaby/guesser.rb +45 -0
- data/lib/wallaby/logger.rb +35 -13
- data/lib/wallaby/map.rb +11 -88
- data/lib/wallaby/preloader.rb +9 -31
- metadata +120 -15
- data/config/locales/wallaby_class.en.yml +0 -9
- data/lib/concerns/wallaby/defaultable.rb +0 -38
- data/lib/concerns/wallaby/shared_helpers.rb +0 -22
- data/lib/services/wallaby/map/model_class_collector.rb +0 -49
- data/lib/services/wallaby/type_renderer.rb +0 -40
- data/lib/utils/wallaby/model_utils.rb +0 -52
- data/lib/utils/wallaby/test_utils.rb +0 -34
@@ -2,99 +2,107 @@
|
|
2
2
|
|
3
3
|
module Wallaby
|
4
4
|
class Configuration
|
5
|
-
#
|
6
|
-
# TODO: remove this from 6.2
|
5
|
+
# @deprecated
|
7
6
|
class Security
|
8
7
|
# Default block to return nil for current user
|
9
|
-
DEFAULT_CURRENT_USER = -> {
|
8
|
+
DEFAULT_CURRENT_USER = -> {}
|
10
9
|
# Default block to return nil
|
11
10
|
DEFAULT_AUTHENTICATE = -> { true }
|
12
11
|
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
#
|
19
|
-
# But once it detects `Devise`, it will use the path that Devise uses without the need of configuration.
|
20
|
-
# @example To update the logout path in `config/initializers/wallaby.rb`
|
21
|
-
# Wallaby.config do |config|
|
22
|
-
# config.security.logout_path = 'logout_path'
|
23
|
-
# end
|
24
|
-
# @since wallaby-5.1.4
|
25
|
-
attr_accessor :logout_path
|
26
|
-
|
27
|
-
# @!attribute logout_method
|
28
|
-
# To globally configure the logout HTTP method.
|
29
|
-
#
|
30
|
-
# Wallaby does not implement any authentication (e.g. login/logout), therefore, logout method will be required
|
31
|
-
# so that Wallaby knows how navigate the user via what HTTP method when user clicks the logout button.
|
32
|
-
#
|
33
|
-
# But once it detects `Devise`, it will use the HTTP method that Devise uses without the need of configuration.
|
34
|
-
# @example To update the logout method in `config/initializers/wallaby.rb`
|
35
|
-
# Wallaby.config do |config|
|
36
|
-
# config.security.logout_method = 'post'
|
37
|
-
# end
|
38
|
-
# @since wallaby-5.1.4
|
39
|
-
attr_accessor :logout_method
|
40
|
-
|
41
|
-
# @!attribute email_method
|
42
|
-
# To globally configure the method on {#current_user} to retrieve email address.
|
43
|
-
#
|
44
|
-
# If no configuration is given, it will attempt to call `email` on {#current_user}.
|
45
|
-
# @example To update the email method in `config/initializers/wallaby.rb`
|
46
|
-
# Wallaby.config do |config|
|
47
|
-
# config.security.email_method = 'email_address'
|
48
|
-
# end
|
49
|
-
# @since wallaby-5.1.4
|
50
|
-
attr_accessor :email_method
|
51
|
-
|
52
|
-
# To globally configure how to get user object.
|
53
|
-
# @example To update how to get the current user object in `config/initializers/wallaby.rb`
|
54
|
-
# Wallaby.config do |config|
|
55
|
-
# config.security.current_user do
|
56
|
-
# User.find_by_email session[:user_email]
|
57
|
-
# end
|
58
|
-
# end
|
59
|
-
# @yield A block to get user object. All application controller methods can be used in the block.
|
60
|
-
def current_user(&block)
|
61
|
-
Logger.deprecated 'Wallaby will remove security.current_user? from 6.2.'
|
62
|
-
if block_given?
|
63
|
-
@current_user = block
|
64
|
-
else
|
65
|
-
@current_user ||= DEFAULT_CURRENT_USER
|
66
|
-
end
|
12
|
+
# @deprecated
|
13
|
+
def logout_path
|
14
|
+
Deprecator.alert 'config.security.logout_path', from: '0.3.0', alternative: <<~INSTRUCTION
|
15
|
+
Please use controller_class.logout_path instead.
|
16
|
+
INSTRUCTION
|
67
17
|
end
|
68
18
|
|
69
|
-
#
|
70
|
-
|
19
|
+
# @deprecated
|
20
|
+
def logout_path=(_logout_path)
|
21
|
+
Deprecator.alert 'config.security.logout_path=', from: '0.3.0', alternative: <<~INSTRUCTION
|
22
|
+
Please use #logout_path= from the controller instead, for example:
|
23
|
+
|
24
|
+
class Admin::ApplicationController < Wallaby::ResourcesController
|
25
|
+
self.logout_path = 'destroy_admin_user_session_path'
|
26
|
+
end
|
27
|
+
INSTRUCTION
|
28
|
+
end
|
29
|
+
|
30
|
+
# @deprecated
|
31
|
+
def logout_method
|
32
|
+
Deprecator.alert 'config.security.logout_method', from: '0.3.0', alternative: <<~INSTRUCTION
|
33
|
+
Please use controller_class.logout_method instead.
|
34
|
+
INSTRUCTION
|
35
|
+
end
|
36
|
+
|
37
|
+
# @deprecated
|
38
|
+
def logout_method=(_logout_method)
|
39
|
+
Deprecator.alert 'config.security.logout_method=', from: '0.3.0', alternative: <<~INSTRUCTION
|
40
|
+
Please use #logout_method= from the controller instead, for example:
|
41
|
+
|
42
|
+
class Admin::ApplicationController < Wallaby::ResourcesController
|
43
|
+
self.logout_method = 'put'
|
44
|
+
end
|
45
|
+
INSTRUCTION
|
46
|
+
end
|
47
|
+
|
48
|
+
# @deprecated
|
49
|
+
def email_method
|
50
|
+
Deprecator.alert 'config.security.email_method', from: '0.3.0', alternative: <<~INSTRUCTION
|
51
|
+
Please use controller_class.email_method instead.
|
52
|
+
INSTRUCTION
|
53
|
+
end
|
54
|
+
|
55
|
+
# @deprecated
|
56
|
+
def email_method=(_email_method)
|
57
|
+
Deprecator.alert 'config.security.email_method=', from: '0.3.0', alternative: <<~INSTRUCTION
|
58
|
+
Please use #email_method= from the controller instead, for example:
|
59
|
+
|
60
|
+
class Admin::ApplicationController < Wallaby::ResourcesController
|
61
|
+
self.email_method = 'email_address'
|
62
|
+
end
|
63
|
+
INSTRUCTION
|
64
|
+
end
|
65
|
+
|
66
|
+
# @deprecated
|
67
|
+
def current_user
|
68
|
+
Deprecator.alert 'config.security.current_user', from: '0.3.0', alternative: <<~INSTRUCTION
|
69
|
+
Please change #wallaby_user from the controller instead, for example:
|
70
|
+
|
71
|
+
class Admin::ApplicationController < Wallaby::ResourcesController
|
72
|
+
def wallaby_user
|
73
|
+
User.find_by_email session[:user_email]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
INSTRUCTION
|
77
|
+
end
|
78
|
+
|
79
|
+
# @deprecated
|
71
80
|
def current_user?
|
72
|
-
current_user
|
81
|
+
Deprecator.alert 'config.security.current_user?', from: '0.3.0', alternative: <<~INSTRUCTION
|
82
|
+
Please use controller#wallaby_user instead.
|
83
|
+
INSTRUCTION
|
73
84
|
end
|
74
85
|
|
75
|
-
#
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
@authenticate = block
|
89
|
-
else
|
90
|
-
@authenticate ||= DEFAULT_AUTHENTICATE
|
91
|
-
end
|
86
|
+
# @deprecated
|
87
|
+
def authenticate
|
88
|
+
Deprecator.alert 'config.security.authenticate', from: '0.3.0', alternative: <<~INSTRUCTION
|
89
|
+
Please change #authenticate_wallaby_user! from the controller instead, for example:
|
90
|
+
|
91
|
+
class Admin::ApplicationController < Wallaby::ResourcesController
|
92
|
+
def authenticate_wallaby_user!
|
93
|
+
authenticate_or_request_with_http_basic do |username, password|
|
94
|
+
username == 'too_simple' && password == 'too_naive'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
INSTRUCTION
|
92
99
|
end
|
93
100
|
|
94
|
-
#
|
95
|
-
# @return [Boolean]
|
101
|
+
# @deprecated
|
96
102
|
def authenticate?
|
97
|
-
|
103
|
+
Deprecator.alert 'config.security.authenicate?', from: '0.3.0', alternative: <<~INSTRUCTION
|
104
|
+
Please use controller#authenticate_wallaby_user! instead.
|
105
|
+
INSTRUCTION
|
98
106
|
end
|
99
107
|
end
|
100
108
|
end
|
@@ -2,26 +2,24 @@
|
|
2
2
|
|
3
3
|
module Wallaby
|
4
4
|
class Configuration
|
5
|
-
#
|
6
|
-
# @since wallaby-5.2.0
|
5
|
+
# @deprecated
|
7
6
|
class Sorting
|
8
|
-
#
|
9
|
-
|
7
|
+
# @deprecated
|
8
|
+
def strategy=(_strategy)
|
9
|
+
Deprecator.alert 'config.sorting.strategy=', from: '0.3.0', alternative: <<~INSTRUCTION
|
10
|
+
Please set #sorting_strategy= from the controller instead, for example:
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
#
|
18
|
-
# @example To enable turbolinks:
|
19
|
-
# Wallaby.config do |config|
|
20
|
-
# config.sorting.strategy = :single
|
21
|
-
# end
|
22
|
-
# @return [Symbol, String]
|
12
|
+
class Admin::ApplicationController < Wallaby::ResourcesController
|
13
|
+
self.sorting_strategy = :multiple
|
14
|
+
end
|
15
|
+
INSTRUCTION
|
16
|
+
end
|
17
|
+
|
18
|
+
# @deprecated
|
23
19
|
def strategy
|
24
|
-
|
20
|
+
Deprecator.alert 'config.sorting.strategy', from: '0.3.0', alternative: <<~INSTRUCTION
|
21
|
+
Please use controller_class.sorting_strategy instead.
|
22
|
+
INSTRUCTION
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
@@ -6,21 +6,27 @@ module Wallaby
|
|
6
6
|
class Configuration
|
7
7
|
include Classifier
|
8
8
|
|
9
|
+
# @!attribute [w] logger
|
10
|
+
attr_writer :logger
|
11
|
+
|
12
|
+
# @!attribute [r] logger
|
13
|
+
def logger
|
14
|
+
@logger ||= Rails.logger
|
15
|
+
end
|
16
|
+
|
9
17
|
# @!attribute [w] model_paths
|
10
18
|
def model_paths=(*model_paths)
|
11
19
|
@model_paths =
|
12
20
|
model_paths.flatten.compact.presence.try do |paths|
|
13
|
-
next paths if paths.all?
|
21
|
+
next paths if paths.all?(String)
|
14
22
|
|
15
|
-
raise
|
16
|
-
ArgumentError,
|
17
|
-
'Please provide a list of string paths, e.g. `["app/models", "app/core"]`'
|
18
|
-
)
|
23
|
+
raise ArgumentError, 'Please provide a list of string paths, e.g. `["app/models", "app/core"]`'
|
19
24
|
end
|
20
25
|
end
|
21
26
|
|
22
27
|
# @!attribute [r] model_paths
|
23
|
-
# To configure the model folders that {
|
28
|
+
# To configure the model folders that {Preloader} needs to load before everything else.
|
29
|
+
# Default is `%w(app/models)`
|
24
30
|
# @example To set the model paths
|
25
31
|
# Wallaby.config do |config|
|
26
32
|
# config.model_paths = ["app/models", "app/core"]
|
@@ -28,18 +34,18 @@ module Wallaby
|
|
28
34
|
# @return [Array<String>] model paths
|
29
35
|
# @since 0.2.2
|
30
36
|
def model_paths
|
31
|
-
@model_paths ||= %w
|
37
|
+
@model_paths ||= %w[app/models]
|
32
38
|
end
|
33
39
|
|
34
40
|
# @!attribute [w] base_controller
|
35
41
|
def base_controller=(base_controller)
|
36
|
-
@base_controller =
|
42
|
+
@base_controller = class_name_of base_controller
|
37
43
|
end
|
38
44
|
|
39
45
|
# @!attribute [r] base_controller
|
40
|
-
# To globally configure the base controller class that {
|
46
|
+
# To globally configure the base controller class that {ResourcesController} should inherit from.
|
41
47
|
#
|
42
|
-
# If no configuration is given, {
|
48
|
+
# If no configuration is given, {ResourcesController} defaults to inherit from **::ApplicationController**
|
43
49
|
# from the host Rails app.
|
44
50
|
# @example To update base controller to `CoreController` in `config/initializers/wallaby.rb`
|
45
51
|
# Wallaby.config do |config|
|
@@ -50,9 +56,34 @@ module Wallaby
|
|
50
56
|
to_class @base_controller ||= '::ApplicationController'
|
51
57
|
end
|
52
58
|
|
53
|
-
#
|
59
|
+
# @!attribute [w] resources_controller
|
60
|
+
def resources_controller=(resources_controller)
|
61
|
+
@resources_controller = class_name_of resources_controller
|
62
|
+
end
|
63
|
+
|
64
|
+
# @!attribute [r] resources_controller
|
65
|
+
# To globally configure the application controller class that {Engine} should use.
|
66
|
+
#
|
67
|
+
# If no configuration is given, {Engine} defaults to use **Admin::ApplicationController** or
|
68
|
+
# {Wallaby::ResourcesController}
|
69
|
+
# from the host Rails app.
|
70
|
+
# @example To update base controller to `CoreController` in `config/initializers/wallaby.rb`
|
71
|
+
# Wallaby.config do |config|
|
72
|
+
# config.resources_controller = ::CoreController
|
73
|
+
# end
|
74
|
+
# @return [Class] base controller class
|
75
|
+
# @since 0.2.3
|
76
|
+
def resources_controller
|
77
|
+
to_class(
|
78
|
+
@resources_controller ||=
|
79
|
+
(to_class('Admin::ApplicationController') && \
|
80
|
+
'Admin::ApplicationController') || 'Wallaby::ResourcesController'
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
# @return [Configuration::Models] models configuration for custom mode
|
54
85
|
def custom_models
|
55
|
-
@custom_models ||=
|
86
|
+
@custom_models ||= ClassArray.new
|
56
87
|
end
|
57
88
|
|
58
89
|
# To globally configure the models for custom mode.
|
@@ -62,12 +93,14 @@ module Wallaby
|
|
62
93
|
# end
|
63
94
|
# @param models [Array<[Class, String]>] a list of model classes/name strings
|
64
95
|
def custom_models=(models)
|
65
|
-
custom_models.
|
96
|
+
@custom_models = ClassArray.new models.flatten
|
66
97
|
end
|
67
98
|
|
68
|
-
# @return [
|
99
|
+
# @return [Configuration::Models] models configuration
|
69
100
|
def models
|
70
|
-
|
101
|
+
Deprecator.alert 'config.models.presence', from: '0.3.0', alternative: <<~INSTRUCTION
|
102
|
+
Please use controller_class.models instead.
|
103
|
+
INSTRUCTION
|
71
104
|
end
|
72
105
|
|
73
106
|
# To globally configure the models that Wallaby should handle.
|
@@ -80,34 +113,36 @@ module Wallaby
|
|
80
113
|
self.models.set models
|
81
114
|
end
|
82
115
|
|
83
|
-
# @return [
|
116
|
+
# @return [Configuration::Security] security configuration
|
84
117
|
def security
|
85
118
|
@security ||= Security.new
|
86
119
|
end
|
87
120
|
|
88
|
-
# @return [
|
121
|
+
# @return [Configuration::Mapping] mapping configuration
|
89
122
|
def mapping
|
90
123
|
@mapping ||= Mapping.new
|
91
124
|
end
|
92
125
|
|
93
|
-
# @return [
|
126
|
+
# @return [Configuration::Metadata] metadata configuration
|
94
127
|
def metadata
|
95
128
|
@metadata ||= Metadata.new
|
96
129
|
end
|
97
130
|
|
98
|
-
# @return [
|
131
|
+
# @return [Configuration::Pagination] pagination configuration
|
99
132
|
def pagination
|
100
133
|
@pagination ||= Pagination.new
|
101
134
|
end
|
102
135
|
|
103
|
-
# @return [
|
136
|
+
# @return [Configuration::Features] features configuration
|
104
137
|
def features
|
105
138
|
@features ||= Features.new
|
106
139
|
end
|
107
140
|
|
108
|
-
# @return [
|
141
|
+
# @return [Configuration::Sorting] sorting configuration
|
109
142
|
def sorting
|
110
|
-
|
143
|
+
Deprecator.alert 'config.sorting.strategy', from: '0.3.0', alternative: <<~INSTRUCTION
|
144
|
+
Please use controller_class.sorting_strategy instead.
|
145
|
+
INSTRUCTION
|
111
146
|
end
|
112
147
|
|
113
148
|
# Clear all configurations
|
@@ -116,7 +151,7 @@ module Wallaby
|
|
116
151
|
end
|
117
152
|
end
|
118
153
|
|
119
|
-
# @return [
|
154
|
+
# @return [Configuration]
|
120
155
|
def self.configuration
|
121
156
|
@configuration ||= Configuration.new
|
122
157
|
end
|
data/lib/wallaby/constants.rb
CHANGED
@@ -9,17 +9,20 @@ module Wallaby
|
|
9
9
|
COLONS = '::' # :nodoc:
|
10
10
|
COMMA = ',' # :nodoc:
|
11
11
|
DOT = '.' # :nodoc:
|
12
|
+
HASH = '#' # :nodoc:
|
13
|
+
HYPHEN = '-' # :nodoc:
|
12
14
|
UNDERSCORE = '_' # :nodoc:
|
13
15
|
PCT = '%' # :nodoc:
|
14
16
|
|
15
|
-
# Default page size for {
|
17
|
+
# Default page size for {Configuration::Pagination#page_size}
|
16
18
|
DEFAULT_PAGE_SIZE = 20
|
17
|
-
# Default max charactoers to display for {
|
19
|
+
# Default max charactoers to display for {Configuration::Metadata#max}
|
18
20
|
DEFAULT_MAX = 20
|
19
21
|
# Default provider name for authorizer sorting.
|
20
22
|
DEFAULT_PROVIDER = 'default'
|
21
23
|
|
22
|
-
|
24
|
+
# HTTP error types that Wallaby handles
|
25
|
+
ERRORS = %i[
|
23
26
|
bad_request
|
24
27
|
forbidden
|
25
28
|
internal_server_error
|
@@ -27,21 +30,26 @@ module Wallaby
|
|
27
30
|
not_implemented
|
28
31
|
unauthorized
|
29
32
|
unprocessable_entity
|
30
|
-
|
31
|
-
MODEL_ACTIONS = %i
|
33
|
+
].freeze
|
34
|
+
MODEL_ACTIONS = %i[index new create show edit update destroy].freeze
|
32
35
|
FORM_ACTIONS = { new: 'form', create: 'form', edit: 'form', update: 'form' }.with_indifferent_access.freeze
|
33
|
-
SAVE_ACTIONS = %w
|
34
|
-
NON_FIND_ACTIONS = %w(index new create).freeze
|
36
|
+
SAVE_ACTIONS = %w[create update].freeze
|
35
37
|
|
36
|
-
SCRIPT_NAME = 'SCRIPT_NAME'
|
37
|
-
PATH_INFO = 'PATH_INFO'
|
38
|
+
SCRIPT_NAME = 'SCRIPT_NAME' # :nodoc:
|
39
|
+
PATH_INFO = 'PATH_INFO' # :nodoc:
|
38
40
|
# Page size list
|
39
|
-
# @see
|
41
|
+
# @see Configuration::Pagination#page_size
|
40
42
|
PERS = [10, 20, 50, 100].freeze
|
41
|
-
CSV = 'csv'
|
42
|
-
WILDCARD = 'QUERY'
|
43
|
-
TITLE_NAMES = %w(name title string text).freeze
|
43
|
+
CSV = 'csv' # :nodoc:
|
44
|
+
WILDCARD = 'QUERY' # :nodoc:
|
44
45
|
|
45
46
|
# A constant of error path for error handling
|
46
47
|
ERROR_PATH = 'error'
|
48
|
+
|
49
|
+
CONTROLLER = 'Controller' # :nodoc:
|
50
|
+
DECORATOR = 'Decorator' # :nodoc:
|
51
|
+
SERVICER = 'Servicer' # :nodoc:
|
52
|
+
AUTHORIZER = 'Authorizer' # :nodoc:
|
53
|
+
PAGINATOR = 'Paginator' # :nodoc:
|
54
|
+
FINDER = 'Finder' # :nodoc:
|
47
55
|
end
|
data/lib/wallaby/core/version.rb
CHANGED
data/lib/wallaby/core.rb
CHANGED
@@ -7,8 +7,10 @@ require 'wallaby/view'
|
|
7
7
|
|
8
8
|
require 'wallaby/core/version'
|
9
9
|
require 'wallaby/constants'
|
10
|
+
require 'wallaby/deprecator'
|
10
11
|
require 'wallaby/logger'
|
11
12
|
require 'wallaby/preloader'
|
13
|
+
require 'wallaby/guesser'
|
12
14
|
require 'wallaby/engine'
|
13
15
|
|
14
16
|
# Global class attributes that holds the most important configuration/information
|
@@ -29,34 +31,39 @@ require 'wallaby/map'
|
|
29
31
|
require 'support/action_dispatch/routing/mapper'
|
30
32
|
|
31
33
|
require 'routes/wallaby/resources_router'
|
34
|
+
require 'routes/wallaby/engines/base_route'
|
35
|
+
require 'routes/wallaby/engines/engine_route'
|
36
|
+
require 'routes/wallaby/engines/custom_app_route'
|
37
|
+
require 'fields/wallaby/all_fields'
|
32
38
|
require 'tree/wallaby/node'
|
33
39
|
require 'parsers/wallaby/parser'
|
34
40
|
|
41
|
+
require 'utils/wallaby/inflector'
|
35
42
|
require 'utils/wallaby/field_utils'
|
36
43
|
require 'utils/wallaby/filter_utils'
|
37
44
|
require 'utils/wallaby/locale'
|
38
|
-
require 'utils/wallaby/model_utils'
|
39
45
|
require 'utils/wallaby/module_utils'
|
40
46
|
require 'utils/wallaby/params_utils'
|
41
|
-
require 'utils/wallaby/test_utils'
|
42
47
|
require 'utils/wallaby/utils'
|
43
48
|
|
44
|
-
require 'concerns/wallaby/application_concern'
|
45
|
-
require 'concerns/wallaby/authentication_concern'
|
46
|
-
require 'concerns/wallaby/resources_concern'
|
47
|
-
|
48
49
|
require 'concerns/wallaby/authorizable'
|
49
50
|
require 'concerns/wallaby/baseable'
|
51
|
+
require 'concerns/wallaby/configurable'
|
52
|
+
require 'concerns/wallaby/urlable'
|
53
|
+
|
50
54
|
require 'concerns/wallaby/decoratable'
|
51
|
-
require 'concerns/wallaby/defaultable'
|
52
55
|
require 'concerns/wallaby/engineable'
|
53
56
|
require 'concerns/wallaby/fieldable'
|
54
57
|
require 'concerns/wallaby/paginatable'
|
55
58
|
require 'concerns/wallaby/prefixable'
|
56
59
|
require 'concerns/wallaby/resourcable'
|
57
60
|
require 'concerns/wallaby/servicable'
|
58
|
-
require 'concerns/wallaby/shared_helpers'
|
59
61
|
|
62
|
+
require 'concerns/wallaby/application_concern'
|
63
|
+
require 'concerns/wallaby/authentication_concern'
|
64
|
+
require 'concerns/wallaby/resources_concern'
|
65
|
+
|
66
|
+
# These are the designed interfaces if you want to get any ORMs to work with Wallaby
|
60
67
|
require 'interfaces/wallaby/mode'
|
61
68
|
require 'interfaces/wallaby/model_decorator'
|
62
69
|
require 'interfaces/wallaby/model_finder'
|
@@ -70,6 +77,7 @@ require 'errors/wallaby/class_not_found'
|
|
70
77
|
require 'errors/wallaby/invalid_error'
|
71
78
|
require 'errors/wallaby/not_implemented'
|
72
79
|
require 'errors/wallaby/not_found'
|
80
|
+
require 'errors/wallaby/method_removed'
|
73
81
|
require 'errors/wallaby/model_not_found'
|
74
82
|
require 'errors/wallaby/resource_not_found'
|
75
83
|
|
@@ -87,13 +95,23 @@ require 'authorizers/wallaby/pundit_authorization_provider'
|
|
87
95
|
|
88
96
|
require 'forms/wallaby/form_builder'
|
89
97
|
|
98
|
+
# These are the service classes responsible
|
99
|
+
# for finding out the controller/decorator/authorizer/servicer/paginator
|
100
|
+
require 'services/wallaby/class_finder'
|
101
|
+
require 'services/wallaby/controller_finder'
|
102
|
+
require 'services/wallaby/decorator_finder'
|
103
|
+
require 'services/wallaby/authorizer_finder'
|
104
|
+
require 'services/wallaby/servicer_finder'
|
105
|
+
require 'services/wallaby/paginator_finder'
|
106
|
+
require 'services/wallaby/default_models_excluder'
|
107
|
+
require 'services/wallaby/fields_regulator'
|
108
|
+
|
90
109
|
require 'services/wallaby/map/mode_mapper'
|
91
|
-
require 'services/wallaby/map/model_class_collector'
|
92
110
|
require 'services/wallaby/map/model_class_mapper'
|
111
|
+
require 'services/wallaby/model_class_filter'
|
93
112
|
require 'services/wallaby/prefixes_builder'
|
94
113
|
require 'services/wallaby/engine_name_finder'
|
95
114
|
require 'services/wallaby/engine_url_for'
|
96
|
-
require 'services/wallaby/type_renderer'
|
97
115
|
require 'services/wallaby/link_options_normalizer'
|
98
116
|
require 'services/wallaby/sorting/hash_builder'
|
99
117
|
require 'services/wallaby/sorting/next_builder'
|
@@ -120,3 +138,9 @@ require 'adaptors/wallaby/custom/model_finder'
|
|
120
138
|
require 'adaptors/wallaby/custom/model_decorator'
|
121
139
|
require 'adaptors/wallaby/custom/model_pagination_provider'
|
122
140
|
require 'adaptors/wallaby/custom/model_service_provider'
|
141
|
+
|
142
|
+
module Wallaby
|
143
|
+
# Core module that can be included by controller
|
144
|
+
module Core
|
145
|
+
end
|
146
|
+
end
|
@@ -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
|
data/lib/wallaby/engine.rb
CHANGED
@@ -5,27 +5,10 @@ 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
|
8
|
+
# @see http://rmosolgo.github.io/blog/2017/04/12/watching-files-during-rails-development/
|
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
|