wallaby-core 0.1.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +60 -13
- data/app/controllers/wallaby/resources_controller.rb +15 -374
- data/app/security/ability.rb +1 -1
- data/config/locales/wallaby.en.yml +92 -128
- data/config/locales/wallaby_class.en.yml +2 -23
- data/lib/adaptors/wallaby/custom/default_provider.rb +1 -1
- data/lib/adaptors/wallaby/custom/model_decorator.rb +8 -7
- data/lib/adaptors/wallaby/custom/model_finder.rb +3 -2
- data/lib/adaptors/wallaby/custom/model_pagination_provider.rb +1 -1
- data/lib/adaptors/wallaby/custom/model_service_provider.rb +1 -40
- data/lib/authorizers/wallaby/cancancan_authorization_provider.rb +30 -24
- data/lib/authorizers/wallaby/default_authorization_provider.rb +6 -13
- data/lib/authorizers/wallaby/model_authorizer.rb +43 -67
- data/lib/authorizers/wallaby/pundit_authorization_provider.rb +21 -30
- data/lib/concerns/wallaby/application_concern.rb +110 -0
- data/lib/concerns/wallaby/authentication_concern.rb +162 -0
- data/lib/concerns/wallaby/authorizable.rb +8 -14
- data/lib/concerns/wallaby/baseable.rb +91 -10
- data/lib/concerns/wallaby/decoratable.rb +3 -3
- data/lib/concerns/wallaby/engineable.rb +1 -1
- data/lib/concerns/wallaby/fieldable.rb +4 -4
- data/lib/concerns/wallaby/paginatable.rb +3 -3
- data/lib/concerns/wallaby/prefixable.rb +21 -0
- data/lib/concerns/wallaby/resourcable.rb +4 -35
- data/lib/concerns/wallaby/resources_concern.rb +434 -0
- data/lib/concerns/wallaby/servicable.rb +4 -10
- data/lib/decorators/wallaby/resource_decorator.rb +53 -80
- data/lib/errors/wallaby/{cell_handling.rb → class_not_found.rb} +1 -1
- data/lib/errors/wallaby/model_not_found.rb +3 -1
- data/lib/errors/wallaby/resource_not_found.rb +1 -1
- data/lib/helpers/wallaby/application_helper.rb +6 -9
- data/lib/helpers/wallaby/form_helper.rb +2 -9
- data/lib/helpers/wallaby/index_helper.rb +2 -14
- data/lib/helpers/wallaby/links_helper.rb +5 -5
- data/lib/helpers/wallaby/resources_helper.rb +3 -7
- data/lib/helpers/wallaby/secure_helper.rb +3 -3
- data/lib/helpers/wallaby/styling_helper.rb +17 -3
- data/lib/interfaces/wallaby/mode.rb +5 -5
- data/lib/interfaces/wallaby/model_authorization_provider.rb +15 -13
- data/lib/interfaces/wallaby/model_decorator.rb +15 -3
- data/lib/paginators/wallaby/model_paginator.rb +14 -45
- data/lib/parsers/wallaby/parser.rb +49 -14
- data/lib/routes/wallaby/resources_router.rb +1 -1
- data/lib/servicers/wallaby/model_servicer.rb +32 -62
- data/lib/services/wallaby/map/mode_mapper.rb +14 -14
- data/lib/services/wallaby/map/model_class_collector.rb +2 -2
- data/lib/services/wallaby/map/model_class_mapper.rb +7 -26
- data/lib/services/wallaby/prefixes_builder.rb +15 -49
- data/lib/services/wallaby/type_renderer.rb +3 -13
- data/lib/utils/wallaby/locale.rb +53 -0
- data/lib/utils/wallaby/model_utils.rb +4 -3
- data/lib/utils/wallaby/module_utils.rb +1 -1
- data/lib/utils/wallaby/utils.rb +10 -15
- data/lib/wallaby/class_array.rb +75 -0
- data/lib/wallaby/class_hash.rb +94 -0
- data/lib/wallaby/classifier.rb +29 -0
- data/lib/wallaby/configuration/mapping.rb +33 -27
- data/lib/wallaby/configuration/metadata.rb +1 -1
- data/lib/wallaby/configuration/models.rb +5 -9
- data/lib/wallaby/configuration/security.rb +6 -3
- data/lib/wallaby/configuration/sorting.rb +1 -1
- data/lib/wallaby/configuration.rb +31 -2
- data/lib/wallaby/constants.rb +10 -8
- data/lib/wallaby/core/version.rb +1 -1
- data/lib/wallaby/core.rb +21 -16
- data/lib/wallaby/engine.rb +9 -20
- data/lib/wallaby/logger.rb +35 -0
- data/lib/wallaby/map.rb +20 -17
- data/lib/wallaby/preloader.rb +77 -0
- metadata +48 -22
- data/app/controllers/wallaby/application_controller.rb +0 -84
- data/app/controllers/wallaby/secure_controller.rb +0 -81
- data/lib/concerns/wallaby/rails_overridden_methods.rb +0 -42
- data/lib/concerns/wallaby/themeable.rb +0 -40
- data/lib/paginators/wallaby/resource_paginator.rb +0 -12
- data/lib/renderers/wallaby/cell.rb +0 -137
- data/lib/renderers/wallaby/cell_resolver.rb +0 -89
- data/lib/renderers/wallaby/custom_lookup_context.rb +0 -64
- data/lib/renderers/wallaby/custom_partial_renderer.rb +0 -33
- data/lib/renderers/wallaby/custom_renderer.rb +0 -16
- data/lib/utils/wallaby/cell_utils.rb +0 -34
- data/lib/utils/wallaby/preload_utils.rb +0 -44
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wallaby
|
4
|
+
# This is a constant-safe hash that stores Class key/value as String
|
5
|
+
# and returns value as Class if it was a Class.
|
6
|
+
#
|
7
|
+
# It can be used for global methods (e.g. {Wallaby::Map.mode_map}) which cache the computed result,
|
8
|
+
# so that when Rails reloads, it won't complain that old Class constants still exist in
|
9
|
+
# ObjectSpace (see https://github.com/wallaby-rails/wallaby/issues/181).
|
10
|
+
#
|
11
|
+
# ```
|
12
|
+
# A copy of SupportAdmin::ApplicationAuthorizer has been removed from the module tree but is still active!
|
13
|
+
# ```
|
14
|
+
#
|
15
|
+
# As there won't be any Class constants being stored, they will converted to String in {#internal} Hash.
|
16
|
+
class ClassHash
|
17
|
+
# @!attribute [r] internal
|
18
|
+
# @return [Hash] The hash to store Class keys/values as String.
|
19
|
+
attr_reader :internal
|
20
|
+
|
21
|
+
# @param [Hash] hash
|
22
|
+
def initialize(hash = {})
|
23
|
+
@internal =
|
24
|
+
(hash || {})
|
25
|
+
.transform_keys(&method(:to_class_name))
|
26
|
+
.transform_values(&method(:to_class_name))
|
27
|
+
end
|
28
|
+
|
29
|
+
# @!attribute [r] origin
|
30
|
+
# @return [Hash] The original hash.
|
31
|
+
def origin
|
32
|
+
# NOTE: DO NOT cache it by using instance variable!
|
33
|
+
@internal
|
34
|
+
.transform_keys(&method(:to_class))
|
35
|
+
.transform_values(&method(:to_class))
|
36
|
+
.reject { |k, v| k.nil? || v.nil? }
|
37
|
+
end
|
38
|
+
|
39
|
+
# @!method keys
|
40
|
+
# Return the keys of {#origin}.
|
41
|
+
delegate :keys, to: :origin
|
42
|
+
|
43
|
+
# @!method values
|
44
|
+
# Return the values of {#origin}.
|
45
|
+
delegate :values, to: :origin
|
46
|
+
|
47
|
+
# @!method ==(other)
|
48
|
+
# Compare #{origin} with other.
|
49
|
+
delegate :==, to: :origin
|
50
|
+
|
51
|
+
# Save the key/value to the {#internal} hash, and convert the Class key/value to String
|
52
|
+
def []=(key, value)
|
53
|
+
@internal[to_class_name(key)] = to_class_name(value)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Return the value for the given key, and convert the value back to Class if it was a Class
|
57
|
+
def [](key)
|
58
|
+
to_class @internal[to_class_name(key)]
|
59
|
+
end
|
60
|
+
|
61
|
+
# @param other [Hash]
|
62
|
+
# @return [Wallaby::ClassHash] new Class hash
|
63
|
+
def merge(other)
|
64
|
+
self.class.new origin.merge(other.try(:origin) || other)
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Wallaby::ClassHash] new Class hash
|
68
|
+
def select(&block)
|
69
|
+
self.class.new origin.select(&block)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Ensure to freeze the {#internal}
|
73
|
+
# @return [Wallaby::ClassHash] self
|
74
|
+
def freeze
|
75
|
+
@internal.freeze
|
76
|
+
super
|
77
|
+
end
|
78
|
+
|
79
|
+
protected
|
80
|
+
|
81
|
+
# Convert to Class name
|
82
|
+
def to_class_name(klass)
|
83
|
+
klass.is_a?(Class) ? [klass.name, true] : [klass, false]
|
84
|
+
end
|
85
|
+
|
86
|
+
# Convert to Class
|
87
|
+
def to_class(pair)
|
88
|
+
val, is_class = pair
|
89
|
+
is_class ? val.constantize : val
|
90
|
+
rescue NameError
|
91
|
+
Logger.error "`#{val}` is not a valid Class name."
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wallaby
|
4
|
+
# Concern to handle the conversion between Class and String
|
5
|
+
module Classifier
|
6
|
+
# Convert Class to String. If not Class, unchanged.
|
7
|
+
# @param klass [Object]
|
8
|
+
# @return [String] if klass is a Class
|
9
|
+
# @return [Object] if klass is not a Class
|
10
|
+
def to_class_name(klass)
|
11
|
+
klass.try(:name) || klass || nil
|
12
|
+
end
|
13
|
+
|
14
|
+
# Convert String to Class. If not String, unchanged.
|
15
|
+
# @param name [Object]
|
16
|
+
# @return [Class] if name is a Class
|
17
|
+
# @return [Object] if name is not a String
|
18
|
+
# @return [nil] if class cannot be found
|
19
|
+
def to_class(name)
|
20
|
+
return name unless name.is_a? String
|
21
|
+
|
22
|
+
# NOTE: DO NOT try to use const_defined? and const_get EVER.
|
23
|
+
# This is Rails, use constantize
|
24
|
+
name.constantize
|
25
|
+
rescue NameError
|
26
|
+
Logger.error "`#{name}` is not a valid Class name."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -3,10 +3,14 @@
|
|
3
3
|
module Wallaby
|
4
4
|
class Configuration
|
5
5
|
# Configuration used in {Wallaby::Map}
|
6
|
-
# @since 5.1.6
|
6
|
+
# @since wallaby-5.1.6
|
7
7
|
class Mapping
|
8
|
+
include Classifier
|
9
|
+
|
8
10
|
# @!attribute [w] resources_controller
|
9
|
-
|
11
|
+
def resources_controller=(resources_controller)
|
12
|
+
@resources_controller = to_class_name resources_controller
|
13
|
+
end
|
10
14
|
|
11
15
|
# @!attribute [r] resources_controller
|
12
16
|
# To globally configure the resources controller.
|
@@ -21,17 +25,19 @@ module Wallaby
|
|
21
25
|
# config.mapping.resources_controller = ::GlobalResourcesController
|
22
26
|
# end
|
23
27
|
# @return [Class] resources controller class
|
24
|
-
# @since 5.1.6
|
28
|
+
# @since wallaby-5.1.6
|
25
29
|
def resources_controller
|
26
30
|
@resources_controller ||=
|
27
31
|
defined?(::Admin::ApplicationController) \
|
28
32
|
&& ::Admin::ApplicationController < ::Wallaby::ResourcesController \
|
29
|
-
&&
|
30
|
-
@resources_controller ||= ResourcesController
|
33
|
+
&& 'Admin::ApplicationController'
|
34
|
+
to_class @resources_controller ||= 'Wallaby::ResourcesController'
|
31
35
|
end
|
32
36
|
|
33
37
|
# @!attribute [w] resource_decorator
|
34
|
-
|
38
|
+
def resource_decorator=(resource_decorator)
|
39
|
+
@resource_decorator = to_class_name resource_decorator
|
40
|
+
end
|
35
41
|
|
36
42
|
# @!attribute [r] resource_decorator
|
37
43
|
# To globally configure the resource decorator.
|
@@ -46,17 +52,19 @@ module Wallaby
|
|
46
52
|
# config.mapping.resource_decorator = ::GlobalResourceDecorator
|
47
53
|
# end
|
48
54
|
# @return [Class] resource decorator class
|
49
|
-
# @since 5.1.6
|
55
|
+
# @since wallaby-5.1.6
|
50
56
|
def resource_decorator
|
51
57
|
@resource_decorator ||=
|
52
58
|
defined?(::Admin::ApplicationDecorator) \
|
53
59
|
&& ::Admin::ApplicationDecorator < ::Wallaby::ResourceDecorator \
|
54
|
-
&&
|
55
|
-
@resource_decorator ||= ResourceDecorator
|
60
|
+
&& 'Admin::ApplicationDecorator'
|
61
|
+
to_class @resource_decorator ||= 'Wallaby::ResourceDecorator'
|
56
62
|
end
|
57
63
|
|
58
64
|
# @!attribute [w] model_servicer
|
59
|
-
|
65
|
+
def model_servicer=(model_servicer)
|
66
|
+
@model_servicer = to_class_name model_servicer
|
67
|
+
end
|
60
68
|
|
61
69
|
# @!attribute [r] model_servicer
|
62
70
|
# To globally configure the model servicer.
|
@@ -71,23 +79,19 @@ module Wallaby
|
|
71
79
|
# config.mapping.model_servicer = ::GlobalModelServicer
|
72
80
|
# end
|
73
81
|
# @return [Class] model servicer class
|
74
|
-
# @since 5.1.6
|
82
|
+
# @since wallaby-5.1.6
|
75
83
|
def model_servicer
|
76
84
|
@model_servicer ||=
|
77
85
|
defined?(::Admin::ApplicationServicer) \
|
78
86
|
&& ::Admin::ApplicationServicer < ::Wallaby::ModelServicer \
|
79
|
-
&&
|
80
|
-
@model_servicer ||= ModelServicer
|
81
|
-
end
|
82
|
-
|
83
|
-
# @deprecated Use {#model_paginator=} instead. It will be removed from 5.3.*
|
84
|
-
def resource_paginator=(resource_paginator)
|
85
|
-
Utils.deprecate 'deprecation.resource_paginator=', caller: caller
|
86
|
-
self.model_paginator = resource_paginator
|
87
|
+
&& 'Admin::ApplicationServicer'
|
88
|
+
to_class @model_servicer ||= 'Wallaby::ModelServicer'
|
87
89
|
end
|
88
90
|
|
89
91
|
# @!attribute [w] model_authorizer
|
90
|
-
|
92
|
+
def model_authorizer=(model_authorizer)
|
93
|
+
@model_authorizer = to_class_name model_authorizer
|
94
|
+
end
|
91
95
|
|
92
96
|
# @!attribute [r] model_authorizer
|
93
97
|
# To globally configure the model authorizer.
|
@@ -102,17 +106,19 @@ module Wallaby
|
|
102
106
|
# config.mapping.model_authorizer = ::GlobalModelAuthorizer
|
103
107
|
# end
|
104
108
|
# @return [Class] model authorizer class
|
105
|
-
# @since 5.2.0
|
109
|
+
# @since wallaby-5.2.0
|
106
110
|
def model_authorizer
|
107
111
|
@model_authorizer ||=
|
108
112
|
defined?(::Admin::ApplicationAuthorizer) \
|
109
113
|
&& ::Admin::ApplicationAuthorizer < ::Wallaby::ModelAuthorizer \
|
110
|
-
&&
|
111
|
-
@model_authorizer ||= ModelAuthorizer
|
114
|
+
&& 'Admin::ApplicationAuthorizer'
|
115
|
+
to_class @model_authorizer ||= 'Wallaby::ModelAuthorizer'
|
112
116
|
end
|
113
117
|
|
114
118
|
# @!attribute [w] model_paginator
|
115
|
-
|
119
|
+
def model_paginator=(model_paginator)
|
120
|
+
@model_paginator = to_class_name model_paginator
|
121
|
+
end
|
116
122
|
|
117
123
|
# @!attribute [r] model_paginator
|
118
124
|
# To globally configure the resource paginator.
|
@@ -127,13 +133,13 @@ module Wallaby
|
|
127
133
|
# config.mapping.model_paginator = ::GlobalModelPaginator
|
128
134
|
# end
|
129
135
|
# @return [Class] resource paginator class
|
130
|
-
# @since 5.2.0
|
136
|
+
# @since wallaby-5.2.0
|
131
137
|
def model_paginator
|
132
138
|
@model_paginator ||=
|
133
139
|
defined?(::Admin::ApplicationPaginator) \
|
134
140
|
&& ::Admin::ApplicationPaginator < ::Wallaby::ModelPaginator \
|
135
|
-
&&
|
136
|
-
@model_paginator ||= ModelPaginator
|
141
|
+
&& 'Admin::ApplicationPaginator'
|
142
|
+
to_class @model_paginator ||= 'Wallaby::ModelPaginator'
|
137
143
|
end
|
138
144
|
end
|
139
145
|
end
|
@@ -2,11 +2,7 @@
|
|
2
2
|
|
3
3
|
module Wallaby
|
4
4
|
class Configuration
|
5
|
-
# @
|
6
|
-
# If constants are cached/stored, they will become stale and Rails will raise conflicts.
|
7
|
-
#
|
8
|
-
# Hence, class name strings should be stored instead.
|
9
|
-
# When classes are requested, strings will be constantized into classes.
|
5
|
+
# @deprecated will move this configuration to {Wallaby::ResourcesController} from 6.2
|
10
6
|
# Models configuration to specify the model classes that Wallaby should handle.
|
11
7
|
class Models
|
12
8
|
# @note If models are whitelisted, models exclusion will NOT be applied.
|
@@ -17,12 +13,12 @@ module Wallaby
|
|
17
13
|
# end
|
18
14
|
# @param models [Array<Class, String>]
|
19
15
|
def set(*models)
|
20
|
-
@models =
|
16
|
+
@models = ClassArray.new(models.flatten)
|
21
17
|
end
|
22
18
|
|
23
19
|
# @return [Array<Class>] the models configured
|
24
20
|
def presence
|
25
|
-
|
21
|
+
@models ||= ClassArray.new # rubocop:disable Naming/MemoizedInstanceVariableName
|
26
22
|
end
|
27
23
|
|
28
24
|
# @note If models are whitelisted using {#set}, models exclusion will NOT be applied.
|
@@ -33,13 +29,13 @@ module Wallaby
|
|
33
29
|
# end
|
34
30
|
# @param models [Array<Class, String>]
|
35
31
|
def exclude(*models)
|
36
|
-
@excludes =
|
32
|
+
@excludes = ClassArray.new(models.flatten)
|
37
33
|
end
|
38
34
|
|
39
35
|
# @return [Array<Class>] the list of models to exclude.
|
40
36
|
# By default, `ActiveRecord::SchemaMigration` is excluded.
|
41
37
|
def excludes
|
42
|
-
|
38
|
+
@excludes ||= ClassArray.new ['ActiveRecord::SchemaMigration']
|
43
39
|
end
|
44
40
|
end
|
45
41
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
module Wallaby
|
4
4
|
class Configuration
|
5
5
|
# Security configuration
|
6
|
+
# TODO: remove this from 6.2
|
6
7
|
class Security
|
7
8
|
# Default block to return nil for current user
|
8
9
|
DEFAULT_CURRENT_USER = -> { nil }
|
@@ -20,7 +21,7 @@ module Wallaby
|
|
20
21
|
# Wallaby.config do |config|
|
21
22
|
# config.security.logout_path = 'logout_path'
|
22
23
|
# end
|
23
|
-
# @since 5.1.4
|
24
|
+
# @since wallaby-5.1.4
|
24
25
|
attr_accessor :logout_path
|
25
26
|
|
26
27
|
# @!attribute logout_method
|
@@ -34,7 +35,7 @@ module Wallaby
|
|
34
35
|
# Wallaby.config do |config|
|
35
36
|
# config.security.logout_method = 'post'
|
36
37
|
# end
|
37
|
-
# @since 5.1.4
|
38
|
+
# @since wallaby-5.1.4
|
38
39
|
attr_accessor :logout_method
|
39
40
|
|
40
41
|
# @!attribute email_method
|
@@ -45,7 +46,7 @@ module Wallaby
|
|
45
46
|
# Wallaby.config do |config|
|
46
47
|
# config.security.email_method = 'email_address'
|
47
48
|
# end
|
48
|
-
# @since 5.1.4
|
49
|
+
# @since wallaby-5.1.4
|
49
50
|
attr_accessor :email_method
|
50
51
|
|
51
52
|
# To globally configure how to get user object.
|
@@ -57,6 +58,7 @@ module Wallaby
|
|
57
58
|
# end
|
58
59
|
# @yield A block to get user object. All application controller methods can be used in the block.
|
59
60
|
def current_user(&block)
|
61
|
+
Logger.deprecated 'Wallaby will remove security.current_user? from 6.2.'
|
60
62
|
if block_given?
|
61
63
|
@current_user = block
|
62
64
|
else
|
@@ -81,6 +83,7 @@ module Wallaby
|
|
81
83
|
# end
|
82
84
|
# @yield A block to authenticate user. All application controller methods can be used in the block.
|
83
85
|
def authenticate(&block)
|
86
|
+
Logger.deprecated 'Wallaby will remove security.authenticate from 6.2.'
|
84
87
|
if block_given?
|
85
88
|
@authenticate = block
|
86
89
|
else
|
@@ -4,8 +4,37 @@
|
|
4
4
|
module Wallaby
|
5
5
|
# Global configuration
|
6
6
|
class Configuration
|
7
|
+
include Classifier
|
8
|
+
|
9
|
+
# @!attribute [w] model_paths
|
10
|
+
def model_paths=(*model_paths)
|
11
|
+
@model_paths =
|
12
|
+
model_paths.flatten.compact.presence.try do |paths|
|
13
|
+
next paths if paths.all? { |p| p.is_a?(String) }
|
14
|
+
|
15
|
+
raise(
|
16
|
+
ArgumentError,
|
17
|
+
'Please provide a list of string paths, e.g. `["app/models", "app/core"]`'
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# @!attribute [r] model_paths
|
23
|
+
# To configure the model folders that {Wallaby::Preloader} needs to load before everything else.
|
24
|
+
# @example To set the model paths
|
25
|
+
# Wallaby.config do |config|
|
26
|
+
# config.model_paths = ["app/models", "app/core"]
|
27
|
+
# end
|
28
|
+
# @return [Array<String>] model paths
|
29
|
+
# @since 0.2.2
|
30
|
+
def model_paths
|
31
|
+
@model_paths ||= %w(app/models)
|
32
|
+
end
|
33
|
+
|
7
34
|
# @!attribute [w] base_controller
|
8
|
-
|
35
|
+
def base_controller=(base_controller)
|
36
|
+
@base_controller = to_class_name base_controller
|
37
|
+
end
|
9
38
|
|
10
39
|
# @!attribute [r] base_controller
|
11
40
|
# To globally configure the base controller class that {Wallaby::ApplicationController} should inherit from.
|
@@ -18,7 +47,7 @@ module Wallaby
|
|
18
47
|
# end
|
19
48
|
# @return [Class] base controller class
|
20
49
|
def base_controller
|
21
|
-
@base_controller ||= ::ApplicationController
|
50
|
+
to_class @base_controller ||= '::ApplicationController'
|
22
51
|
end
|
23
52
|
|
24
53
|
# @return [Wallaby::Configuration::Models] models configuration for custom mode
|
data/lib/wallaby/constants.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Wallaby
|
4
|
-
EMPTY_STRING = ''.html_safe
|
5
|
-
EMPTY_HASH = {}.freeze
|
6
|
-
EMPTY_ARRAY = [].freeze
|
7
|
-
SPACE = ' '
|
8
|
-
SLASH = '/'
|
9
|
-
COLONS = '::'
|
10
|
-
COMMA = ','
|
11
|
-
DOT = '.'
|
4
|
+
EMPTY_STRING = ''.html_safe.freeze # :nodoc:
|
5
|
+
EMPTY_HASH = {}.freeze # :nodoc:
|
6
|
+
EMPTY_ARRAY = [].freeze # :nodoc:
|
7
|
+
SPACE = ' ' # :nodoc:
|
8
|
+
SLASH = '/' # :nodoc:
|
9
|
+
COLONS = '::' # :nodoc:
|
10
|
+
COMMA = ',' # :nodoc:
|
11
|
+
DOT = '.' # :nodoc:
|
12
|
+
UNDERSCORE = '_' # :nodoc:
|
13
|
+
PCT = '%' # :nodoc:
|
12
14
|
|
13
15
|
# Default page size for {Wallaby::Configuration::Pagination#page_size}
|
14
16
|
DEFAULT_PAGE_SIZE = 20
|
data/lib/wallaby/core/version.rb
CHANGED
data/lib/wallaby/core.rb
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'active_model'
|
3
4
|
require 'parslet'
|
4
5
|
require 'responders'
|
6
|
+
require 'wallaby/view'
|
5
7
|
|
6
8
|
require 'wallaby/core/version'
|
7
9
|
require 'wallaby/constants'
|
10
|
+
require 'wallaby/logger'
|
11
|
+
require 'wallaby/preloader'
|
8
12
|
require 'wallaby/engine'
|
9
13
|
|
10
|
-
|
11
|
-
|
14
|
+
# Global class attributes that holds the most important configuration/information
|
15
|
+
# NOTE: DO NOT store any Class in both configuration and map
|
16
|
+
require 'wallaby/classifier'
|
17
|
+
require 'wallaby/class_array'
|
18
|
+
require 'wallaby/class_hash'
|
12
19
|
require 'wallaby/configuration'
|
13
20
|
require 'wallaby/configuration/features'
|
14
21
|
require 'wallaby/configuration/mapping'
|
@@ -19,20 +26,25 @@ require 'wallaby/configuration/security'
|
|
19
26
|
require 'wallaby/configuration/sorting'
|
20
27
|
require 'wallaby/map'
|
21
28
|
|
29
|
+
require 'support/action_dispatch/routing/mapper'
|
30
|
+
|
22
31
|
require 'routes/wallaby/resources_router'
|
23
32
|
require 'tree/wallaby/node'
|
24
33
|
require 'parsers/wallaby/parser'
|
25
34
|
|
26
|
-
require 'utils/wallaby/cell_utils'
|
27
35
|
require 'utils/wallaby/field_utils'
|
28
36
|
require 'utils/wallaby/filter_utils'
|
37
|
+
require 'utils/wallaby/locale'
|
29
38
|
require 'utils/wallaby/model_utils'
|
30
39
|
require 'utils/wallaby/module_utils'
|
31
40
|
require 'utils/wallaby/params_utils'
|
32
|
-
require 'utils/wallaby/preload_utils'
|
33
41
|
require 'utils/wallaby/test_utils'
|
34
42
|
require 'utils/wallaby/utils'
|
35
43
|
|
44
|
+
require 'concerns/wallaby/application_concern'
|
45
|
+
require 'concerns/wallaby/authentication_concern'
|
46
|
+
require 'concerns/wallaby/resources_concern'
|
47
|
+
|
36
48
|
require 'concerns/wallaby/authorizable'
|
37
49
|
require 'concerns/wallaby/baseable'
|
38
50
|
require 'concerns/wallaby/decoratable'
|
@@ -40,11 +52,10 @@ require 'concerns/wallaby/defaultable'
|
|
40
52
|
require 'concerns/wallaby/engineable'
|
41
53
|
require 'concerns/wallaby/fieldable'
|
42
54
|
require 'concerns/wallaby/paginatable'
|
43
|
-
require 'concerns/wallaby/
|
55
|
+
require 'concerns/wallaby/prefixable'
|
44
56
|
require 'concerns/wallaby/resourcable'
|
45
57
|
require 'concerns/wallaby/servicable'
|
46
58
|
require 'concerns/wallaby/shared_helpers'
|
47
|
-
require 'concerns/wallaby/themeable'
|
48
59
|
|
49
60
|
require 'interfaces/wallaby/mode'
|
50
61
|
require 'interfaces/wallaby/model_decorator'
|
@@ -54,12 +65,13 @@ require 'interfaces/wallaby/model_pagination_provider'
|
|
54
65
|
require 'interfaces/wallaby/model_authorization_provider'
|
55
66
|
|
56
67
|
require 'errors/wallaby/general_error'
|
68
|
+
|
69
|
+
require 'errors/wallaby/class_not_found'
|
57
70
|
require 'errors/wallaby/invalid_error'
|
58
71
|
require 'errors/wallaby/not_implemented'
|
59
72
|
require 'errors/wallaby/not_found'
|
60
73
|
require 'errors/wallaby/model_not_found'
|
61
74
|
require 'errors/wallaby/resource_not_found'
|
62
|
-
require 'errors/wallaby/cell_handling'
|
63
75
|
|
64
76
|
require 'errors/wallaby/forbidden'
|
65
77
|
require 'errors/wallaby/not_authenticated'
|
@@ -68,7 +80,6 @@ require 'errors/wallaby/unprocessable_entity'
|
|
68
80
|
require 'decorators/wallaby/resource_decorator'
|
69
81
|
require 'servicers/wallaby/model_servicer'
|
70
82
|
require 'paginators/wallaby/model_paginator'
|
71
|
-
require 'paginators/wallaby/resource_paginator'
|
72
83
|
require 'authorizers/wallaby/model_authorizer'
|
73
84
|
require 'authorizers/wallaby/default_authorization_provider'
|
74
85
|
require 'authorizers/wallaby/cancancan_authorization_provider'
|
@@ -96,19 +107,13 @@ require 'helpers/wallaby/links_helper'
|
|
96
107
|
require 'helpers/wallaby/styling_helper'
|
97
108
|
|
98
109
|
require 'helpers/wallaby/base_helper'
|
99
|
-
require 'helpers/wallaby/resources_helper'
|
100
|
-
require 'helpers/wallaby/secure_helper'
|
101
110
|
require 'helpers/wallaby/application_helper'
|
111
|
+
require 'helpers/wallaby/secure_helper'
|
112
|
+
require 'helpers/wallaby/resources_helper'
|
102
113
|
|
103
114
|
require 'responders/wallaby/resources_responder'
|
104
115
|
require 'responders/wallaby/json_api_responder'
|
105
116
|
|
106
|
-
require 'renderers/wallaby/cell'
|
107
|
-
require 'renderers/wallaby/cell_resolver'
|
108
|
-
require 'renderers/wallaby/custom_lookup_context'
|
109
|
-
require 'renderers/wallaby/custom_renderer'
|
110
|
-
require 'renderers/wallaby/custom_partial_renderer'
|
111
|
-
|
112
117
|
require 'adaptors/wallaby/custom'
|
113
118
|
require 'adaptors/wallaby/custom/default_provider'
|
114
119
|
require 'adaptors/wallaby/custom/model_finder'
|
data/lib/wallaby/engine.rb
CHANGED
@@ -3,40 +3,29 @@
|
|
3
3
|
module Wallaby
|
4
4
|
# Wallaby engine
|
5
5
|
class Engine < ::Rails::Engine
|
6
|
-
initializer 'wallaby.autoload_paths', before: :set_load_path do |_|
|
7
|
-
# NOTE: this needs to be run before `set_load_path`
|
8
|
-
# so that files under `app/views` can be eager loaded
|
9
|
-
# and therefore, Wallaby's renderer can function properly
|
10
|
-
[Rails.configuration].each do |conf|
|
11
|
-
next if conf.paths['app/views'].eager_load?
|
12
|
-
|
13
|
-
conf.paths.add 'app/views', eager_load: true
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
6
|
initializer 'wallaby.development.reload' do |_|
|
18
7
|
# NOTE: Rails reload! will hit here
|
19
8
|
# @see http://rmosolgo.github.io/blog/2017/04/12/watching-files-during-rails-development/
|
20
9
|
config.to_prepare do
|
21
10
|
if Rails.env.development? || Rails.configuration.eager_load
|
22
|
-
|
23
|
-
|
24
|
-
|
11
|
+
Logger.debug 'Reloading after Rails\' reload...', sourcing: false
|
12
|
+
Map.clear
|
13
|
+
Preloader.require_all
|
25
14
|
end
|
26
15
|
end
|
27
16
|
end
|
28
17
|
|
29
18
|
config.before_eager_load do
|
30
|
-
# NOTE:
|
31
|
-
|
32
|
-
|
19
|
+
# NOTE: The models must be loaded before everything else
|
20
|
+
Logger.debug 'Preload all `app/models` files.', sourcing: false
|
21
|
+
Preloader.require_models
|
33
22
|
end
|
34
23
|
|
35
|
-
# Preload the rest files
|
36
24
|
config.after_initialize do
|
25
|
+
# Load the rest files
|
37
26
|
unless Rails.env.development? || Rails.configuration.eager_load
|
38
|
-
|
39
|
-
|
27
|
+
Logger.debug 'Preload all other eager load files after initialize.', sourcing: false
|
28
|
+
Preloader.require_all
|
40
29
|
end
|
41
30
|
end
|
42
31
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wallaby
|
4
|
+
# Custom logger
|
5
|
+
module Logger
|
6
|
+
class << self
|
7
|
+
%i(unknown fatal error warn info debug deprecated).each do |method_id|
|
8
|
+
define_method method_id do |message, replacements = {}|
|
9
|
+
sourcing = replacements.delete :sourcing # sourcing can be set to false
|
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,
|
14
|
+
"#{heading}#{method_id.to_s.upcase}: #{format new_message, replacements}#{from}"
|
15
|
+
)
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
# @param message [Object]
|
23
|
+
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")}"]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|