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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +60 -13
  3. data/app/controllers/wallaby/resources_controller.rb +15 -374
  4. data/app/security/ability.rb +1 -1
  5. data/config/locales/wallaby.en.yml +92 -128
  6. data/config/locales/wallaby_class.en.yml +2 -23
  7. data/lib/adaptors/wallaby/custom/default_provider.rb +1 -1
  8. data/lib/adaptors/wallaby/custom/model_decorator.rb +8 -7
  9. data/lib/adaptors/wallaby/custom/model_finder.rb +3 -2
  10. data/lib/adaptors/wallaby/custom/model_pagination_provider.rb +1 -1
  11. data/lib/adaptors/wallaby/custom/model_service_provider.rb +1 -40
  12. data/lib/authorizers/wallaby/cancancan_authorization_provider.rb +30 -24
  13. data/lib/authorizers/wallaby/default_authorization_provider.rb +6 -13
  14. data/lib/authorizers/wallaby/model_authorizer.rb +43 -67
  15. data/lib/authorizers/wallaby/pundit_authorization_provider.rb +21 -30
  16. data/lib/concerns/wallaby/application_concern.rb +110 -0
  17. data/lib/concerns/wallaby/authentication_concern.rb +162 -0
  18. data/lib/concerns/wallaby/authorizable.rb +8 -14
  19. data/lib/concerns/wallaby/baseable.rb +91 -10
  20. data/lib/concerns/wallaby/decoratable.rb +3 -3
  21. data/lib/concerns/wallaby/engineable.rb +1 -1
  22. data/lib/concerns/wallaby/fieldable.rb +4 -4
  23. data/lib/concerns/wallaby/paginatable.rb +3 -3
  24. data/lib/concerns/wallaby/prefixable.rb +21 -0
  25. data/lib/concerns/wallaby/resourcable.rb +4 -35
  26. data/lib/concerns/wallaby/resources_concern.rb +434 -0
  27. data/lib/concerns/wallaby/servicable.rb +4 -10
  28. data/lib/decorators/wallaby/resource_decorator.rb +53 -80
  29. data/lib/errors/wallaby/{cell_handling.rb → class_not_found.rb} +1 -1
  30. data/lib/errors/wallaby/model_not_found.rb +3 -1
  31. data/lib/errors/wallaby/resource_not_found.rb +1 -1
  32. data/lib/helpers/wallaby/application_helper.rb +6 -9
  33. data/lib/helpers/wallaby/form_helper.rb +2 -9
  34. data/lib/helpers/wallaby/index_helper.rb +2 -14
  35. data/lib/helpers/wallaby/links_helper.rb +5 -5
  36. data/lib/helpers/wallaby/resources_helper.rb +3 -7
  37. data/lib/helpers/wallaby/secure_helper.rb +3 -3
  38. data/lib/helpers/wallaby/styling_helper.rb +17 -3
  39. data/lib/interfaces/wallaby/mode.rb +5 -5
  40. data/lib/interfaces/wallaby/model_authorization_provider.rb +15 -13
  41. data/lib/interfaces/wallaby/model_decorator.rb +15 -3
  42. data/lib/paginators/wallaby/model_paginator.rb +14 -45
  43. data/lib/parsers/wallaby/parser.rb +49 -14
  44. data/lib/routes/wallaby/resources_router.rb +1 -1
  45. data/lib/servicers/wallaby/model_servicer.rb +32 -62
  46. data/lib/services/wallaby/map/mode_mapper.rb +14 -14
  47. data/lib/services/wallaby/map/model_class_collector.rb +2 -2
  48. data/lib/services/wallaby/map/model_class_mapper.rb +7 -26
  49. data/lib/services/wallaby/prefixes_builder.rb +15 -49
  50. data/lib/services/wallaby/type_renderer.rb +3 -13
  51. data/lib/utils/wallaby/locale.rb +53 -0
  52. data/lib/utils/wallaby/model_utils.rb +4 -3
  53. data/lib/utils/wallaby/module_utils.rb +1 -1
  54. data/lib/utils/wallaby/utils.rb +10 -15
  55. data/lib/wallaby/class_array.rb +75 -0
  56. data/lib/wallaby/class_hash.rb +94 -0
  57. data/lib/wallaby/classifier.rb +29 -0
  58. data/lib/wallaby/configuration/mapping.rb +33 -27
  59. data/lib/wallaby/configuration/metadata.rb +1 -1
  60. data/lib/wallaby/configuration/models.rb +5 -9
  61. data/lib/wallaby/configuration/security.rb +6 -3
  62. data/lib/wallaby/configuration/sorting.rb +1 -1
  63. data/lib/wallaby/configuration.rb +31 -2
  64. data/lib/wallaby/constants.rb +10 -8
  65. data/lib/wallaby/core/version.rb +1 -1
  66. data/lib/wallaby/core.rb +21 -16
  67. data/lib/wallaby/engine.rb +9 -20
  68. data/lib/wallaby/logger.rb +35 -0
  69. data/lib/wallaby/map.rb +20 -17
  70. data/lib/wallaby/preloader.rb +77 -0
  71. metadata +48 -22
  72. data/app/controllers/wallaby/application_controller.rb +0 -84
  73. data/app/controllers/wallaby/secure_controller.rb +0 -81
  74. data/lib/concerns/wallaby/rails_overridden_methods.rb +0 -42
  75. data/lib/concerns/wallaby/themeable.rb +0 -40
  76. data/lib/paginators/wallaby/resource_paginator.rb +0 -12
  77. data/lib/renderers/wallaby/cell.rb +0 -137
  78. data/lib/renderers/wallaby/cell_resolver.rb +0 -89
  79. data/lib/renderers/wallaby/custom_lookup_context.rb +0 -64
  80. data/lib/renderers/wallaby/custom_partial_renderer.rb +0 -33
  81. data/lib/renderers/wallaby/custom_renderer.rb +0 -16
  82. data/lib/utils/wallaby/cell_utils.rb +0 -34
  83. data/lib/utils/wallaby/preload_utils.rb +0 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8395907973df19277e9cb9a726b2c0ec37ea3ad7cbea4ea009447c9c71c17f4a
4
- data.tar.gz: c4a7d6d916973748ab861950818697a834a28c0ef1b614ce11ef6ba377a56847
3
+ metadata.gz: 6a09ac87dc23eae2c29466d9b92c72323c8fab161353006fe23d588f17281929
4
+ data.tar.gz: 3803dcb490c18109c73bd2b375466dfc00326f4448366d8699028bd6be0c4d33
5
5
  SHA512:
6
- metadata.gz: 77cbf958df5073c15ee4a20c00c2f9aaba1898136294e84b54ddeb82257c82d7c29f40084a5fa5c9f4788d65bb132a336033ff47dc2302f3ae7543f7ccaeb6e9
7
- data.tar.gz: 4b3ba5ff82410c0e63996be5358e2a9f33084f65ed45331531957431e3eb5ec36e8fb140e845ae4c6615d7ab67d5dc1efb0cc0ac34510e770819a08e8f8419a1
6
+ metadata.gz: 53c39759f03f5ecfc69653a6240bb705dcd6a765139db9b62fcc87680cb0524aab5406d9a0250c8f1eb1613e6982763f73d11993e08609d9629e0bb3b028d4b6
7
+ data.tar.gz: 3228ddfcacb5d686a8f42fc3ea1b79139f3cdf724503c5d2ae2b10de4722bca44525a3d9c06dfd66abcd2ea719d4a7d28092b0a996b89ef0953a606c00340e26
data/README.md CHANGED
@@ -1,31 +1,78 @@
1
- # Wallaby::Core
1
+ # [Wallaby::Core](https://github.com/wallaby-rails/wallaby-core)
2
2
 
3
- This gem contains the core interface that Wallaby is built upon.
3
+ [![Gem Version](https://badge.fury.io/rb/wallaby-core.svg)](https://badge.fury.io/rb/wallaby-core)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![Travis CI](https://travis-ci.com/wallaby-rails/wallaby-core.svg?branch=master)](https://travis-ci.com/wallaby-rails/wallaby-core)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/f16f8d87553424c1aacc/maintainability)](https://codeclimate.com/github/wallaby-rails/wallaby-core/maintainability)
7
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/f16f8d87553424c1aacc/test_coverage)](https://codeclimate.com/github/wallaby-rails/wallaby-core/test_coverage)
8
+ [![Inch CI](https://inch-ci.org/github/wallaby-rails/wallaby-core.svg?branch=master)](https://inch-ci.org/github/wallaby-rails/wallaby-core)
4
9
 
5
- ## Installation
10
+ **Wallaby::Core** holds all the core interfaces that [Wallaby](https://github.com/wallaby-rails/wallaby) gem is built upon.
6
11
 
7
- Add this line to your application's Gemfile:
12
+ ## Install
13
+
14
+ Add `Wallaby::Core` to `Gemfile`.
8
15
 
9
16
  ```ruby
10
17
  gem 'wallaby-core'
11
18
  ```
12
19
 
13
- And then execute:
20
+ And re-bundle.
14
21
 
15
22
  ```shell
16
- $ bundle
23
+ bundle install
17
24
  ```
18
25
 
19
- Or install it yourself as:
26
+ ## Documentation
20
27
 
21
- ```shell
22
- $ gem install wallaby-core
23
- ```
28
+ - [API Reference](https://www.rubydoc.info/gems/wallaby-core)
29
+ - [Change Logs](https://github.com/wallaby-rails/wallaby-core/blob/master/CHANGELOG.md)
30
+
31
+ ## Build, test and update document
32
+
33
+ To set up local development environment:
34
+
35
+ - git clone this repo
36
+ - install Ruby (2.4 ~ 3.0)
37
+ - install gems
38
+
39
+ ```shell
40
+ bundle install
41
+ ```
42
+
43
+ - install both MySQL and PostgreSQL
44
+ - create databases
45
+
46
+ ```shell
47
+ bundle exec rake db:create
48
+ ```
49
+
50
+ - start developing
51
+
52
+ Make sure to pass the following checks and tests before putting up a PR:
53
+
54
+ - rubocop analysis and format check
55
+
56
+ ```shell
57
+ bundle exec rubocop -a
58
+ ```
59
+
60
+ - rspec test suites and 100% test coverage
61
+
62
+ ```shell
63
+ RAILS_ENV=test bundle exec rake --trace spec
64
+ ```
65
+
66
+ - update the comments and build the yardoc
67
+
68
+ ```shell
69
+ yardoc
70
+ ```
24
71
 
25
- ## Contributing
72
+ ## Want to contribute?
26
73
 
27
- Bug reports and pull requests are welcome on GitHub at https://github.com/wallaby-rails/wallaby-core.
74
+ Raise an [issue](https://github.com/wallaby-rails/wallaby-core/issues/new), discuss and resolve!
28
75
 
29
76
  ## License
30
77
 
31
- This project is [MIT Licensed](LICENSE)
78
+ This project uses [MIT License](https://github.com/wallaby-rails/wallaby-core/blob/master/LICENSE).
@@ -1,381 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wallaby
4
+ ResourcesController = Class.new configuration.base_controller
5
+
4
6
  # Resources controller, superclass for all customization controllers.
5
- # It contains CRUD template action methods (`index`/`new`/`create`/`edit`/`update`/`destroy`)
7
+ # It contains CRUD template action methods
8
+ # ({Wallaby::ResourcesConcern#index #index} / {Wallaby::ResourcesConcern#new #new}
9
+ # / {Wallaby::ResourcesConcern#create #create} / {Wallaby::ResourcesConcern#edit #edit}
10
+ # / {Wallaby::ResourcesConcern#update #update} / {Wallaby::ResourcesConcern#destroy #destroy})
6
11
  # that allow subclasses to override.
7
- class ResourcesController < ::Wallaby::SecureController
8
- extend Authorizable::ClassMethods
9
- extend Baseable::ClassMethods
10
- extend Decoratable::ClassMethods
11
- extend Paginatable::ClassMethods
12
- extend Resourcable::ClassMethods
13
- extend Servicable::ClassMethods
14
- extend Themeable::ClassMethods
15
- include Authorizable
16
- include Decoratable
17
- include Defaultable
18
- include Paginatable
19
- include RailsOverriddenMethods
20
- include Resourcable
21
- include Servicable
22
- include Themeable
23
-
24
- self.responder = ResourcesResponder
25
- respond_to :html
26
- respond_to :json
27
- respond_to :csv, only: :index
28
- helper ResourcesHelper
29
- before_action :authenticate_user!
30
-
31
- # @note This is a template method that can be overridden by subclasses.
32
- # This is an action for landing page display. It does nothing more than rendering `home` template.
33
- #
34
- # It can be replaced completely in subclasses as below:
35
- #
36
- # ```
37
- # def home
38
- # generate_dashboard_report
39
- # end
40
- # ```
41
- def home
42
- # do nothing
43
- end
44
-
45
- # @note This is a template method that can be overridden by subclasses.
46
- # This is a resourceful action to list records that user can access.
47
- #
48
- # It can be customized as below in subclasses:
49
- #
50
- # `WARN: Please keep in mind that Wallaby User Interface requires **index**
51
- # action to respond to **csv** and **json** format as well.`
52
- #
53
- # ```
54
- # def index
55
- # # do something before the origin action
56
- # options = {} # NOTE: see `options` parameter for more details
57
- # index!(options) do |format| # NOTE: this is better than using `super`
58
- # # NOTE: this block is for `respond_with` which works similar to `respond_to`
59
- # # customize response behaviour, or do something before the request is rendered
60
- # end
61
- # end
62
- # ```
63
- #
64
- # Otherwise, it can be replaced completely in subclasses:
65
- #
66
- # `WARN: Please keep in mind that Wallaby User Interface requires **index**
67
- # action to respond to **csv** and **json** format as well.`
68
- #
69
- # ```
70
- # def index
71
- # # NOTE: `@collection` will be used by the view, please ensure it is assigned, for example:
72
- # @collection = Product.all
73
- # respond_with @collection
74
- # end
75
- # ```
76
- # @param options [Hash] (since 5.2.0) options for
77
- # {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
78
- # respond_with}
79
- # @yield [format] block for
80
- # {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
81
- # respond_with}
82
- # to customize response behaviour.
83
- # @raise [Wallaby::Forbidden] if user has no access
84
- def index(options = {}, &block)
85
- current_authorizer.authorize :index, current_model_class
86
- respond_with collection, options, &block
87
- end
88
-
89
- alias index! index
90
-
91
- # @note This is a template method that can be overridden by subclasses.
92
- # This is a resourceful action to show the form to create record that user is allowed to.
93
- #
94
- # It can be customized as below in subclasses:
95
- #
96
- # ```
97
- # def new
98
- # # do something before the origin action
99
- # options = {} # NOTE: see `options` parameter for more details
100
- # new!(options) do |format| # NOTE: this is better than using `super`
101
- # # NOTE: this block is for `respond_with` which works similar to `respond_to`
102
- # # customize response behaviour, or do something before the request is rendered
103
- # end
104
- # end
105
- # ```
106
- #
107
- # Otherwise, it can be replaced completely in subclasses:
108
- #
109
- # ```
110
- # def new
111
- # # NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
112
- # @resource = Product.new new_arrival: true
113
- # end
114
- # ```
115
- # @param options [Hash] (since 5.2.0) options for
116
- # {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
117
- # respond_with}
118
- # @yield [format] block for
119
- # {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
120
- # respond_with}
121
- # to customize response behaviour.
122
- # @raise [Wallaby::Forbidden] if user has no access
123
- def new(options = {}, &block)
124
- current_authorizer.authorize :new, resource
125
- respond_with resource, options, &block
126
- end
127
-
128
- alias new! new
129
-
130
- # @note This is a template method that can be overridden by subclasses.
131
- # This is a resourceful action to create a record that user is allowed to.
132
- #
133
- # If record is created successfully, user will be navigated to the record show page.
134
- # Otherwise, the form will be shown again with error messages.
135
- #
136
- # It can be customized as below in subclasses:
137
- #
138
- # ```
139
- # def create
140
- # # do something before the origin action
141
- # options = {} # NOTE: see `options` parameter for more details
142
- # create!(options) do |format| # NOTE: this is better than using `super`
143
- # # NOTE: this block is for `respond_with` which works similar to `respond_to`
144
- # # customize response behaviour, or do something before the request is rendered
145
- # end
146
- # end
147
- # ```
148
- #
149
- # Otherwise, it can be replaced completely in subclasses:
150
- #
151
- # ```
152
- # def create
153
- # # NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
154
- # @resource = Product.new resource_params.merge(new_arrival: true)
155
- # if @resource.save
156
- # redirect_to helper.index_path(current_model_class)
157
- # else
158
- # render :new
159
- # end
160
- # end
161
- # ```
162
- # @param options [Hash] (since 5.2.0) options for
163
- # {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
164
- # respond_with}. In addition, options `:params` is supported, see below
165
- # @option options [ActionController::Parameters, Hash] :params
166
- # permitted parameters for servicer to create the record. _(defaults to: {#resource_params})_
167
- # @yield [format] block for
168
- # {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
169
- # respond_with}
170
- # to customize response behaviour.
171
- # @raise [Wallaby::Forbidden] if user has no access
172
- def create(options = {}, &block)
173
- set_defaults_for :create, options
174
- current_authorizer.authorize :create, resource
175
- current_servicer.create resource, options.delete(:params)
176
- respond_with resource, options, &block
177
- end
178
-
179
- alias create! create
180
-
181
- # @note This is a template method that can be overridden by subclasses.
182
- # This is a resourceful action to display the record details that user is allowed to.
183
- #
184
- # It can be customized as below in subclasses:
185
- #
186
- # ```
187
- # def show
188
- # # do something before the origin action
189
- # options = {} # NOTE: see `options` parameter for more details
190
- # show!(options) do |format| # NOTE: this is better than using `super`
191
- # # NOTE: this block is for `respond_with` which works similar to `respond_to`
192
- # # customize response behaviour, or do something before the request is rendered
193
- # end
194
- # end
195
- # ```
196
- #
197
- # Otherwise, it can be replaced completely in subclasses:
198
- #
199
- # ```
200
- # def show
201
- # # NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
202
- # @resource = Product.find_by_slug params[:id]
203
- # end
204
- # ```
205
- # @param options [Hash] (since 5.2.0) options for
206
- # {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
207
- # respond_with}
208
- # @yield [format] block for
209
- # {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
210
- # respond_with}
211
- # to customize response behaviour.
212
- # @raise [Wallaby::Forbidden] if user has no access
213
- def show(options = {}, &block)
214
- current_authorizer.authorize :show, resource
215
- respond_with resource, options, &block
216
- end
217
-
218
- alias show! show
219
-
220
- # @note This is a template method that can be overridden by subclasses.
221
- # This is a resourceful action to show the form to edit record that user is allowed to.
222
- #
223
- # It can be customized as below in subclasses:
224
- #
225
- # ```
226
- # def edit
227
- # # do something before the origin action
228
- # options = {} # NOTE: see `options` parameter for more details
229
- # edit!(options) do |format| # NOTE: this is better than using `super`
230
- # # NOTE: this block is for `respond_with` which works similar to `respond_to`
231
- # # customize response behaviour, or do something before the request is rendered
232
- # end
233
- # end
234
- # ```
235
- #
236
- # Otherwise, it can be replaced completely in subclasses:
237
- #
238
- # ```
239
- # def edit
240
- # # NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
241
- # @resource = Product.find_by_slug params[:id]
242
- # end
243
- # ```
244
- # @param options [Hash] (since 5.2.0) options for
245
- # {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
246
- # respond_with}
247
- # @yield [format] block for
248
- # {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
249
- # respond_with}
250
- # to customize response behaviour.
251
- # @raise [Wallaby::Forbidden] if user has no access
252
- def edit(options = {}, &block)
253
- current_authorizer.authorize :edit, resource
254
- respond_with resource, options, &block
255
- end
256
-
257
- alias edit! edit
258
-
259
- # @note This is a template method that can be overridden by subclasses.
260
- # This is a resourceful action to update the record that user is allowed to.
261
- #
262
- # If record is updated successfully, user will be navigated to the record show page.
263
- # Otherwise, the form will be shown again with error messages.
264
- #
265
- # It can be customized as below in subclasses:
266
- #
267
- # ```
268
- # def update
269
- # # do something before the origin action
270
- # options = {} # NOTE: see `options` parameter for more details
271
- # update!(options) do |format| # NOTE: this is better than using `super`
272
- # # NOTE: this block is for `respond_with` which works similar to `respond_to`
273
- # # customize response behaviour, or do something before the request is rendered
274
- # end
275
- # end
276
- # ```
277
- #
278
- # Otherwise, it can be replaced completely in subclasses:
279
- #
280
- # ```
281
- # def update
282
- # # NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
283
- # @resource = Product.find_by_slug params[:id]
284
- # @resource.assign_attributes resource_params.merge(new_arrival: true)
285
- # if @resource.save
286
- # redirect_to helper.index_path(current_model_class)
287
- # else
288
- # render :new
289
- # end
290
- # end
291
- # ```
292
- # @param options [Hash] (since 5.2.0) options for
293
- # {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
294
- # respond_with}. In addition, options `:params` is supported, see below
295
- # @option options [ActionController::Parameters, Hash] :params
296
- # permitted parameters for servicer to update the record. _(defaults to: {#resource_params})_
297
- # @yield [format] block for
298
- # {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
299
- # respond_with}
300
- # to customize response behaviour.
301
- # @raise [Wallaby::Forbidden] if user has no access
302
- def update(options = {}, &block)
303
- set_defaults_for :update, options
304
- current_authorizer.authorize :update, resource
305
- current_servicer.update resource, options.delete(:params)
306
- respond_with resource, options, &block
307
- end
308
-
309
- alias update! update
310
-
311
- # @note This is a template method that can be overridden by subclasses.
312
- # This is a resourceful action to delete the record that user is allowed to.
313
- #
314
- # It can be customized as below in subclasses:
315
- #
316
- # ```
317
- # def destroy
318
- # # do something before the origin action
319
- # options = {} # NOTE: see `options` parameter for more details
320
- # destroy!(options) do |format| # NOTE: this is better than using `super`
321
- # # NOTE: this block is for `respond_with` which works similar to `respond_to`
322
- # # customize response behaviour, or do something before the request is rendered
323
- # end
324
- # end
325
- # ```
326
- #
327
- # Otherwise, it can be replaced completely in subclasses:
328
- #
329
- # ```
330
- # def destroy
331
- # # NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
332
- # @resource = Product.find_by_slug params[:id]
333
- # @resource.destroy
334
- # redirect_to helper.index_path(current_model_class)
335
- # end
336
- # ```
337
- # @param options [Hash] (since 5.2.0) options for
338
- # {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
339
- # respond_with}. In addition, options `:params` is supported, see below
340
- # @option options [ActionController::Parameters, Hash] :params
341
- # permitted parameters for servicer to destroy the record. _(defaults to: {#resource_params})_
342
- # @yield [format] block for
343
- # {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
344
- # respond_with}
345
- # to customize response behaviour.
346
- # @raise [Wallaby::Forbidden] if user has no access
347
- def destroy(options = {}, &block)
348
- set_defaults_for :destroy, options
349
- current_authorizer.authorize :destroy, resource
350
- current_servicer.destroy resource, options.delete(:params)
351
- respond_with resource, options, &block
352
- end
353
-
354
- alias destroy! destroy
355
-
356
- # @note This is a template method that can be overridden by subclasses.
357
- # To whitelist the params for {#create} and {#update} actions.
358
- #
359
- # If Wallaby cannot generate the correct strong parameters, it can be replaced, for example:
360
- #
361
- # ```
362
- # def resource_params
363
- # params.fetch(:product, {}).permit(:name, :sku)
364
- # end
365
- # ```
366
- # @return [ActionController::Parameters] whitelisted params
367
- def resource_params
368
- @resource_params ||= current_servicer.permit params, action_name
369
- end
370
-
371
- # @!method collection(options = {}, &block)
372
- # (see Wallaby::Resourcable#collection)
373
- # @see Wallaby::Resourcable#collection
374
- alias collection! collection
375
-
376
- # @!method resource(options = {}, &block)
377
- # (see Wallaby::Resourcable#resource)
378
- # @see Wallaby::Resourcable#resource
379
- alias resource! resource
12
+ #
13
+ # For better practice, please create an application controller class (see example)
14
+ # to better control the functions shared between different resource controllers.
15
+ # @example Create an application class for Admin Interface usage
16
+ # class Admin::ApplicationController < Wallaby::ResourcesController
17
+ # base_class!
18
+ # end
19
+ class ResourcesController
20
+ include ResourcesConcern
380
21
  end
381
22
  end
@@ -4,7 +4,7 @@
4
4
  # Defualt ability for wallaby
5
5
  # If main app has defined `ability.rb`, this file will not be loaded/used.
6
6
  class Ability
7
- include ::CanCan::Ability
7
+ include ::CanCan::Ability if defined?(::CanCan)
8
8
 
9
9
  # @param _user [Object]
10
10
  def initialize(_user)