wallaby-core 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +31 -0
- data/app/controllers/wallaby/application_controller.rb +84 -0
- data/app/controllers/wallaby/resources_controller.rb +381 -0
- data/app/controllers/wallaby/secure_controller.rb +81 -0
- data/app/security/ability.rb +13 -0
- data/config/locales/wallaby.en.yml +140 -0
- data/config/locales/wallaby_class.en.yml +30 -0
- data/config/routes.rb +39 -0
- data/lib/adaptors/wallaby/custom.rb +7 -0
- data/lib/adaptors/wallaby/custom/default_provider.rb +9 -0
- data/lib/adaptors/wallaby/custom/model_decorator.rb +71 -0
- data/lib/adaptors/wallaby/custom/model_finder.rb +13 -0
- data/lib/adaptors/wallaby/custom/model_pagination_provider.rb +14 -0
- data/lib/adaptors/wallaby/custom/model_service_provider.rb +48 -0
- data/lib/authorizers/wallaby/cancancan_authorization_provider.rb +72 -0
- data/lib/authorizers/wallaby/default_authorization_provider.rb +58 -0
- data/lib/authorizers/wallaby/model_authorizer.rb +100 -0
- data/lib/authorizers/wallaby/pundit_authorization_provider.rb +89 -0
- data/lib/concerns/wallaby/authorizable.rb +103 -0
- data/lib/concerns/wallaby/baseable.rb +36 -0
- data/lib/concerns/wallaby/decoratable.rb +101 -0
- data/lib/concerns/wallaby/defaultable.rb +38 -0
- data/lib/concerns/wallaby/engineable.rb +61 -0
- data/lib/concerns/wallaby/fieldable.rb +78 -0
- data/lib/concerns/wallaby/paginatable.rb +72 -0
- data/lib/concerns/wallaby/rails_overridden_methods.rb +42 -0
- data/lib/concerns/wallaby/resourcable.rb +149 -0
- data/lib/concerns/wallaby/servicable.rb +68 -0
- data/lib/concerns/wallaby/shared_helpers.rb +22 -0
- data/lib/concerns/wallaby/themeable.rb +40 -0
- data/lib/decorators/wallaby/resource_decorator.rb +189 -0
- data/lib/errors/wallaby/cell_handling.rb +6 -0
- data/lib/errors/wallaby/forbidden.rb +6 -0
- data/lib/errors/wallaby/general_error.rb +6 -0
- data/lib/errors/wallaby/invalid_error.rb +6 -0
- data/lib/errors/wallaby/model_not_found.rb +11 -0
- data/lib/errors/wallaby/not_authenticated.rb +6 -0
- data/lib/errors/wallaby/not_found.rb +6 -0
- data/lib/errors/wallaby/not_implemented.rb +6 -0
- data/lib/errors/wallaby/resource_not_found.rb +11 -0
- data/lib/errors/wallaby/unprocessable_entity.rb +6 -0
- data/lib/forms/wallaby/form_builder.rb +60 -0
- data/lib/helpers/wallaby/application_helper.rb +79 -0
- data/lib/helpers/wallaby/base_helper.rb +65 -0
- data/lib/helpers/wallaby/configuration_helper.rb +18 -0
- data/lib/helpers/wallaby/form_helper.rb +62 -0
- data/lib/helpers/wallaby/index_helper.rb +84 -0
- data/lib/helpers/wallaby/links_helper.rb +213 -0
- data/lib/helpers/wallaby/resources_helper.rb +52 -0
- data/lib/helpers/wallaby/secure_helper.rb +54 -0
- data/lib/helpers/wallaby/styling_helper.rb +82 -0
- data/lib/interfaces/wallaby/mode.rb +72 -0
- data/lib/interfaces/wallaby/model_authorization_provider.rb +99 -0
- data/lib/interfaces/wallaby/model_decorator.rb +168 -0
- data/lib/interfaces/wallaby/model_finder.rb +12 -0
- data/lib/interfaces/wallaby/model_pagination_provider.rb +107 -0
- data/lib/interfaces/wallaby/model_service_provider.rb +84 -0
- data/lib/paginators/wallaby/model_paginator.rb +115 -0
- data/lib/paginators/wallaby/resource_paginator.rb +12 -0
- data/lib/parsers/wallaby/parser.rb +34 -0
- data/lib/renderers/wallaby/cell.rb +137 -0
- data/lib/renderers/wallaby/cell_resolver.rb +89 -0
- data/lib/renderers/wallaby/custom_lookup_context.rb +64 -0
- data/lib/renderers/wallaby/custom_partial_renderer.rb +33 -0
- data/lib/renderers/wallaby/custom_renderer.rb +16 -0
- data/lib/responders/wallaby/json_api_responder.rb +101 -0
- data/lib/responders/wallaby/resources_responder.rb +28 -0
- data/lib/routes/wallaby/resources_router.rb +72 -0
- data/lib/servicers/wallaby/model_servicer.rb +154 -0
- data/lib/services/wallaby/engine_name_finder.rb +22 -0
- data/lib/services/wallaby/engine_url_for.rb +46 -0
- data/lib/services/wallaby/link_options_normalizer.rb +19 -0
- data/lib/services/wallaby/map/mode_mapper.rb +27 -0
- data/lib/services/wallaby/map/model_class_collector.rb +49 -0
- data/lib/services/wallaby/map/model_class_mapper.rb +38 -0
- data/lib/services/wallaby/prefixes_builder.rb +66 -0
- data/lib/services/wallaby/sorting/hash_builder.rb +19 -0
- data/lib/services/wallaby/sorting/link_builder.rb +69 -0
- data/lib/services/wallaby/sorting/next_builder.rb +63 -0
- data/lib/services/wallaby/sorting/single_builder.rb +20 -0
- data/lib/services/wallaby/type_renderer.rb +50 -0
- data/lib/support/action_dispatch/routing/mapper.rb +75 -0
- data/lib/tree/wallaby/node.rb +25 -0
- data/lib/utils/wallaby/cell_utils.rb +34 -0
- data/lib/utils/wallaby/field_utils.rb +43 -0
- data/lib/utils/wallaby/filter_utils.rb +20 -0
- data/lib/utils/wallaby/model_utils.rb +51 -0
- data/lib/utils/wallaby/module_utils.rb +46 -0
- data/lib/utils/wallaby/params_utils.rb +14 -0
- data/lib/utils/wallaby/preload_utils.rb +44 -0
- data/lib/utils/wallaby/test_utils.rb +34 -0
- data/lib/utils/wallaby/utils.rb +27 -0
- data/lib/wallaby/configuration.rb +103 -0
- data/lib/wallaby/configuration/features.rb +24 -0
- data/lib/wallaby/configuration/mapping.rb +140 -0
- data/lib/wallaby/configuration/metadata.rb +23 -0
- data/lib/wallaby/configuration/models.rb +46 -0
- data/lib/wallaby/configuration/pagination.rb +30 -0
- data/lib/wallaby/configuration/security.rb +98 -0
- data/lib/wallaby/configuration/sorting.rb +28 -0
- data/lib/wallaby/constants.rb +45 -0
- data/lib/wallaby/core.rb +117 -0
- data/lib/wallaby/core/version.rb +7 -0
- data/lib/wallaby/engine.rb +43 -0
- data/lib/wallaby/map.rb +170 -0
- metadata +222 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wallaby
|
4
|
+
# Utils
|
5
|
+
module Utils
|
6
|
+
# Display deprecate message including the line where it's used
|
7
|
+
# @param key [String]
|
8
|
+
# @param caller [String] the line where it's called
|
9
|
+
# @param options [Hash]
|
10
|
+
def self.deprecate(key, caller:, options: {})
|
11
|
+
warn I18n.t(key, options.merge(from: caller[0]))
|
12
|
+
end
|
13
|
+
|
14
|
+
# @deprecated Use {Wallaby::FilterUtils.filter_name_by} instead. It will be removed from 5.3.*
|
15
|
+
def self.find_filter_name(filter_name, filters)
|
16
|
+
deprecate 'deprecation.find_filter_name', caller: caller
|
17
|
+
FilterUtils.filter_name_by filter_name, filters
|
18
|
+
end
|
19
|
+
|
20
|
+
# @see http://stackoverflow.com/a/8710663/1326499
|
21
|
+
# @param object [Object]
|
22
|
+
# @return [Object] a clone object
|
23
|
+
def self.clone(object)
|
24
|
+
::Marshal.load(::Marshal.dump(object))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Wallaby
|
4
|
+
module Wallaby
|
5
|
+
# Global configuration
|
6
|
+
class Configuration
|
7
|
+
# @!attribute [w] base_controller
|
8
|
+
attr_writer :base_controller
|
9
|
+
|
10
|
+
# @!attribute [r] base_controller
|
11
|
+
# To globally configure the base controller class that {Wallaby::ApplicationController} should inherit from.
|
12
|
+
#
|
13
|
+
# If no configuration is given, {Wallaby::ApplicationController} defaults to inherit from `::ApplicationController`
|
14
|
+
# from the host Rails app.
|
15
|
+
# @example To update base controller to `CoreController` in `config/initializers/wallaby.rb`
|
16
|
+
# Wallaby.config do |config|
|
17
|
+
# config.base_controller = ::CoreController
|
18
|
+
# end
|
19
|
+
# @return [Class] base controller class
|
20
|
+
def base_controller
|
21
|
+
@base_controller ||= ::ApplicationController
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Wallaby::Configuration::Models] models configuration for custom mode
|
25
|
+
def custom_models
|
26
|
+
@custom_models ||= Models.new
|
27
|
+
end
|
28
|
+
|
29
|
+
# To globally configure the models for custom mode.
|
30
|
+
# @example To update the model classes in `config/initializers/wallaby.rb`
|
31
|
+
# Wallaby.config do |config|
|
32
|
+
# config.custom_models = [Product, Order]
|
33
|
+
# end
|
34
|
+
# @param models [Array<[Class, String]>] a list of model classes/name strings
|
35
|
+
def custom_models=(models)
|
36
|
+
custom_models.set models
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Wallaby::Configuration::Models] models configuration
|
40
|
+
def models
|
41
|
+
@models ||= Models.new
|
42
|
+
end
|
43
|
+
|
44
|
+
# To globally configure the models that Wallaby should handle.
|
45
|
+
# @example To update the model classes in `config/initializers/wallaby.rb`
|
46
|
+
# Wallaby.config do |config|
|
47
|
+
# config.models = [Product, Order]
|
48
|
+
# end
|
49
|
+
# @param models [Array<[Class, String]>] a list of model classes/name strings
|
50
|
+
def models=(models)
|
51
|
+
self.models.set models
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Wallaby::Configuration::Security] security configuration
|
55
|
+
def security
|
56
|
+
@security ||= Security.new
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [Wallaby::Configuration::Mapping] mapping configuration
|
60
|
+
def mapping
|
61
|
+
@mapping ||= Mapping.new
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [Wallaby::Configuration::Metadata] metadata configuration
|
65
|
+
def metadata
|
66
|
+
@metadata ||= Metadata.new
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [Wallaby::Configuration::Pagination] pagination configuration
|
70
|
+
def pagination
|
71
|
+
@pagination ||= Pagination.new
|
72
|
+
end
|
73
|
+
|
74
|
+
# @return [Wallaby::Configuration::Features] features configuration
|
75
|
+
def features
|
76
|
+
@features ||= Features.new
|
77
|
+
end
|
78
|
+
|
79
|
+
# @return [Wallaby::Configuration::Sorting] sorting configuration
|
80
|
+
def sorting
|
81
|
+
@sorting ||= Sorting.new
|
82
|
+
end
|
83
|
+
|
84
|
+
# Clear all configurations
|
85
|
+
def clear
|
86
|
+
instance_variables.each { |name| instance_variable_set name, nil }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# @return [Wallaby::Configuration]
|
91
|
+
def self.configuration
|
92
|
+
@configuration ||= Configuration.new
|
93
|
+
end
|
94
|
+
|
95
|
+
# To config settings using a block
|
96
|
+
# @example
|
97
|
+
# Wallaby.config do |c|
|
98
|
+
# c.pagination.page_size = 20
|
99
|
+
# end
|
100
|
+
def self.config
|
101
|
+
yield configuration
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wallaby
|
4
|
+
class Configuration
|
5
|
+
# Features global configuration
|
6
|
+
class Features
|
7
|
+
# @!attribute [w] turbolinks_enabled
|
8
|
+
attr_writer :turbolinks_enabled
|
9
|
+
|
10
|
+
# @!attribute [r] turbolinks_enabled
|
11
|
+
# To globally configure whether to use turbolinks or not.
|
12
|
+
#
|
13
|
+
# By default, turbolinks is disabled.
|
14
|
+
# @example To enable turbolinks:
|
15
|
+
# Wallaby.config do |config|
|
16
|
+
# config.features.turbolinks_enabled = true
|
17
|
+
# end
|
18
|
+
# @return [Boolean] a feture flag of turbolinks, default to false.
|
19
|
+
def turbolinks_enabled
|
20
|
+
@turbolinks_enabled ||= false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wallaby
|
4
|
+
class Configuration
|
5
|
+
# Configuration used in {Wallaby::Map}
|
6
|
+
# @since 5.1.6
|
7
|
+
class Mapping
|
8
|
+
# @!attribute [w] resources_controller
|
9
|
+
attr_writer :resources_controller
|
10
|
+
|
11
|
+
# @!attribute [r] resources_controller
|
12
|
+
# To globally configure the resources controller.
|
13
|
+
#
|
14
|
+
# If no configuration is given, Wallaby will look up from the following controller classes
|
15
|
+
# and use the first available one:
|
16
|
+
#
|
17
|
+
# - ::Admin::ApplicationController (only when it inherits from {Wallaby::ResourcesController})
|
18
|
+
# - {Wallaby::ResourcesController}
|
19
|
+
# @example To update the resources controller to `GlobalResourcesController` in `config/initializers/wallaby.rb`
|
20
|
+
# Wallaby.config do |config|
|
21
|
+
# config.mapping.resources_controller = ::GlobalResourcesController
|
22
|
+
# end
|
23
|
+
# @return [Class] resources controller class
|
24
|
+
# @since 5.1.6
|
25
|
+
def resources_controller
|
26
|
+
@resources_controller ||=
|
27
|
+
defined?(::Admin::ApplicationController) \
|
28
|
+
&& ::Admin::ApplicationController < ::Wallaby::ResourcesController \
|
29
|
+
&& ::Admin::ApplicationController
|
30
|
+
@resources_controller ||= ResourcesController
|
31
|
+
end
|
32
|
+
|
33
|
+
# @!attribute [w] resource_decorator
|
34
|
+
attr_writer :resource_decorator
|
35
|
+
|
36
|
+
# @!attribute [r] resource_decorator
|
37
|
+
# To globally configure the resource decorator.
|
38
|
+
#
|
39
|
+
# If no configuration is given, Wallaby will look up from the following decorator classes
|
40
|
+
# and use the first available one:
|
41
|
+
#
|
42
|
+
# - ::Admin::ApplicationDecorator (only when it inherits from {Wallaby::ResourceDecorator})
|
43
|
+
# - {Wallaby::ResourceDecorator}
|
44
|
+
# @example To update the resource decorator to `GlobalResourceDecorator` in `config/initializers/wallaby.rb`
|
45
|
+
# Wallaby.config do |config|
|
46
|
+
# config.mapping.resource_decorator = ::GlobalResourceDecorator
|
47
|
+
# end
|
48
|
+
# @return [Class] resource decorator class
|
49
|
+
# @since 5.1.6
|
50
|
+
def resource_decorator
|
51
|
+
@resource_decorator ||=
|
52
|
+
defined?(::Admin::ApplicationDecorator) \
|
53
|
+
&& ::Admin::ApplicationDecorator < ::Wallaby::ResourceDecorator \
|
54
|
+
&& ::Admin::ApplicationDecorator
|
55
|
+
@resource_decorator ||= ResourceDecorator
|
56
|
+
end
|
57
|
+
|
58
|
+
# @!attribute [w] model_servicer
|
59
|
+
attr_writer :model_servicer
|
60
|
+
|
61
|
+
# @!attribute [r] model_servicer
|
62
|
+
# To globally configure the model servicer.
|
63
|
+
#
|
64
|
+
# If no configuration is given, Wallaby will look up from the following servicer classes
|
65
|
+
# and use the first available one:
|
66
|
+
#
|
67
|
+
# - ::Admin::ApplicationServicer (only when it inherits from {Wallaby::ModelServicer})
|
68
|
+
# - {Wallaby::ModelServicer}
|
69
|
+
# @example To update the model servicer to `GlobalModelServicer` in `config/initializers/wallaby.rb`
|
70
|
+
# Wallaby.config do |config|
|
71
|
+
# config.mapping.model_servicer = ::GlobalModelServicer
|
72
|
+
# end
|
73
|
+
# @return [Class] model servicer class
|
74
|
+
# @since 5.1.6
|
75
|
+
def model_servicer
|
76
|
+
@model_servicer ||=
|
77
|
+
defined?(::Admin::ApplicationServicer) \
|
78
|
+
&& ::Admin::ApplicationServicer < ::Wallaby::ModelServicer \
|
79
|
+
&& ::Admin::ApplicationServicer
|
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
|
+
end
|
88
|
+
|
89
|
+
# @!attribute [w] model_authorizer
|
90
|
+
attr_writer :model_authorizer
|
91
|
+
|
92
|
+
# @!attribute [r] model_authorizer
|
93
|
+
# To globally configure the model authorizer.
|
94
|
+
#
|
95
|
+
# If no configuration is given, Wallaby will look up from the following authorizer classes
|
96
|
+
# and use the first available one:
|
97
|
+
#
|
98
|
+
# - ::Admin::ApplicationAuthorizer (only when it inherits from {Wallaby::ModelAuthorizer})
|
99
|
+
# - {Wallaby::ModelAuthorizer}
|
100
|
+
# @example To update the model authorizer to `GlobalModelAuthorizer` in `config/initializers/wallaby.rb`
|
101
|
+
# Wallaby.config do |config|
|
102
|
+
# config.mapping.model_authorizer = ::GlobalModelAuthorizer
|
103
|
+
# end
|
104
|
+
# @return [Class] model authorizer class
|
105
|
+
# @since 5.2.0
|
106
|
+
def model_authorizer
|
107
|
+
@model_authorizer ||=
|
108
|
+
defined?(::Admin::ApplicationAuthorizer) \
|
109
|
+
&& ::Admin::ApplicationAuthorizer < ::Wallaby::ModelAuthorizer \
|
110
|
+
&& ::Admin::ApplicationAuthorizer
|
111
|
+
@model_authorizer ||= ModelAuthorizer
|
112
|
+
end
|
113
|
+
|
114
|
+
# @!attribute [w] model_paginator
|
115
|
+
attr_writer :model_paginator
|
116
|
+
|
117
|
+
# @!attribute [r] model_paginator
|
118
|
+
# To globally configure the resource paginator.
|
119
|
+
#
|
120
|
+
# If no configuration is given, Wallaby will look up from the following paginator classes
|
121
|
+
# and use the first available one:
|
122
|
+
#
|
123
|
+
# - ::Admin::ApplicationPaginator (only when it inherits from {Wallaby::ModelPaginator})
|
124
|
+
# - {Wallaby::ModelPaginator}
|
125
|
+
# @example To update the resource paginator to `GlobalModelPaginator` in `config/initializers/wallaby.rb`
|
126
|
+
# Wallaby.config do |config|
|
127
|
+
# config.mapping.model_paginator = ::GlobalModelPaginator
|
128
|
+
# end
|
129
|
+
# @return [Class] resource paginator class
|
130
|
+
# @since 5.2.0
|
131
|
+
def model_paginator
|
132
|
+
@model_paginator ||=
|
133
|
+
defined?(::Admin::ApplicationPaginator) \
|
134
|
+
&& ::Admin::ApplicationPaginator < ::Wallaby::ModelPaginator \
|
135
|
+
&& ::Admin::ApplicationPaginator
|
136
|
+
@model_paginator ||= ModelPaginator
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wallaby
|
4
|
+
class Configuration
|
5
|
+
# Metadata configuration
|
6
|
+
class Metadata
|
7
|
+
# @!attribute [w] max
|
8
|
+
attr_writer :max
|
9
|
+
|
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 5.1.6
|
18
|
+
def max
|
19
|
+
@max ||= DEFAULT_MAX
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wallaby
|
4
|
+
class Configuration
|
5
|
+
# @note In `development` environment, Rails recreates module/class constants on reload event.
|
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.
|
10
|
+
# Models configuration to specify the model classes that Wallaby should handle.
|
11
|
+
class Models
|
12
|
+
# @note If models are whitelisted, models exclusion will NOT be applied.
|
13
|
+
# To globally configure what model classes that Wallaby should handle.
|
14
|
+
# @example To whitelist the model classes in `config/initializers/wallaby.rb`
|
15
|
+
# Wallaby.config do |config|
|
16
|
+
# config.models = [Product, Order]
|
17
|
+
# end
|
18
|
+
# @param models [Array<Class, String>]
|
19
|
+
def set(*models)
|
20
|
+
@models = Array(models).flatten.map(&:to_s)
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [Array<Class>] the models configured
|
24
|
+
def presence
|
25
|
+
(@models ||= []).map(&:constantize)
|
26
|
+
end
|
27
|
+
|
28
|
+
# @note If models are whitelisted using {#set}, models exclusion will NOT be applied.
|
29
|
+
# To globally configure what model classes to exclude.
|
30
|
+
# @example To exclude models in `config/initializers/wallaby.rb`
|
31
|
+
# Wallaby.config do |config|
|
32
|
+
# config.models.exclude Product, Order
|
33
|
+
# end
|
34
|
+
# @param models [Array<Class, String>]
|
35
|
+
def exclude(*models)
|
36
|
+
@excludes = Array(models).flatten.map(&:to_s)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Array<Class>] the list of models to exclude.
|
40
|
+
# By default, `ActiveRecord::SchemaMigration` is excluded.
|
41
|
+
def excludes
|
42
|
+
(@excludes ||= ['ActiveRecord::SchemaMigration']).map(&:constantize)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wallaby
|
4
|
+
class Configuration
|
5
|
+
# Pagination configuration
|
6
|
+
class Pagination
|
7
|
+
# @!attribute [w] page_size
|
8
|
+
attr_writer :page_size
|
9
|
+
|
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
|
25
|
+
def page_size
|
26
|
+
@page_size ||= DEFAULT_PAGE_SIZE
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wallaby
|
4
|
+
class Configuration
|
5
|
+
# Security configuration
|
6
|
+
class Security
|
7
|
+
# Default block to return nil for current user
|
8
|
+
DEFAULT_CURRENT_USER = -> { nil }
|
9
|
+
# Default block to return nil
|
10
|
+
DEFAULT_AUTHENTICATE = -> { true }
|
11
|
+
|
12
|
+
# @!attribute logout_path
|
13
|
+
# To globally configure the logout path.
|
14
|
+
#
|
15
|
+
# Wallaby does not implement any authentication (e.g. login/logout), therefore, logout path will be required
|
16
|
+
# so that Wallaby knows where to navigate the user to when user clicks the logout button.
|
17
|
+
#
|
18
|
+
# But once it detects `Devise`, it will use the path that Devise uses without the need of configuration.
|
19
|
+
# @example To update the logout path in `config/initializers/wallaby.rb`
|
20
|
+
# Wallaby.config do |config|
|
21
|
+
# config.security.logout_path = 'logout_path'
|
22
|
+
# end
|
23
|
+
# @since 5.1.4
|
24
|
+
attr_accessor :logout_path
|
25
|
+
|
26
|
+
# @!attribute logout_method
|
27
|
+
# To globally configure the logout HTTP method.
|
28
|
+
#
|
29
|
+
# Wallaby does not implement any authentication (e.g. login/logout), therefore, logout method will be required
|
30
|
+
# so that Wallaby knows how navigate the user via what HTTP method when user clicks the logout button.
|
31
|
+
#
|
32
|
+
# But once it detects `Devise`, it will use the HTTP method that Devise uses without the need of configuration.
|
33
|
+
# @example To update the logout method in `config/initializers/wallaby.rb`
|
34
|
+
# Wallaby.config do |config|
|
35
|
+
# config.security.logout_method = 'post'
|
36
|
+
# end
|
37
|
+
# @since 5.1.4
|
38
|
+
attr_accessor :logout_method
|
39
|
+
|
40
|
+
# @!attribute email_method
|
41
|
+
# To globally configure the method on {#current_user} to retrieve email address.
|
42
|
+
#
|
43
|
+
# If no configuration is given, it will attempt to call `email` on {#current_user}.
|
44
|
+
# @example To update the email method in `config/initializers/wallaby.rb`
|
45
|
+
# Wallaby.config do |config|
|
46
|
+
# config.security.email_method = 'email_address'
|
47
|
+
# end
|
48
|
+
# @since 5.1.4
|
49
|
+
attr_accessor :email_method
|
50
|
+
|
51
|
+
# To globally configure how to get user object.
|
52
|
+
# @example To update how to get the current user object in `config/initializers/wallaby.rb`
|
53
|
+
# Wallaby.config do |config|
|
54
|
+
# config.security.current_user do
|
55
|
+
# User.find_by_email session[:user_email]
|
56
|
+
# end
|
57
|
+
# end
|
58
|
+
# @yield A block to get user object. All application controller methods can be used in the block.
|
59
|
+
def current_user(&block)
|
60
|
+
if block_given?
|
61
|
+
@current_user = block
|
62
|
+
else
|
63
|
+
@current_user ||= DEFAULT_CURRENT_USER
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Check if {#current_user} configuration is set.
|
68
|
+
# @return [Boolean]
|
69
|
+
def current_user?
|
70
|
+
current_user != DEFAULT_CURRENT_USER
|
71
|
+
end
|
72
|
+
|
73
|
+
# To globally configure how to authenicate a user.
|
74
|
+
# @example
|
75
|
+
# Wallaby.config do |config|
|
76
|
+
# config.security.authenticate do
|
77
|
+
# authenticate_or_request_with_http_basic do |username, password|
|
78
|
+
# username == 'too_simple' && password == 'too_naive'
|
79
|
+
# end
|
80
|
+
# end
|
81
|
+
# end
|
82
|
+
# @yield A block to authenticate user. All application controller methods can be used in the block.
|
83
|
+
def authenticate(&block)
|
84
|
+
if block_given?
|
85
|
+
@authenticate = block
|
86
|
+
else
|
87
|
+
@authenticate ||= DEFAULT_AUTHENTICATE
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Check if {#authenticate} configuration is set.
|
92
|
+
# @return [Boolean]
|
93
|
+
def authenticate?
|
94
|
+
authenticate != DEFAULT_AUTHENTICATE
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|