skinny_controllers 0.10.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cba81691573f9ad4648dcacb2733234c5ef4cd5
4
- data.tar.gz: cb4d9ff187f35d0cd097da6675ed3de9f74115db
3
+ metadata.gz: d020916e740eec6d6047321f6797499deedd91a9
4
+ data.tar.gz: 38f090da8386787f87ceaaa58ab37e6b8653cd38
5
5
  SHA512:
6
- metadata.gz: 64f11e00970ccbca44700ff970e54cb92a3b0e5d107b80949d03c6f2bf98deca88774f0a39c71b2b6fd3b2b4dceeae34adccba483deef8f55a7c82a2e799ea76
7
- data.tar.gz: 6a96956ac79c335072e0755388bb86bd40df665454e57781553090011caa90bbf36ba51a79d1a040dd2cb15d6a59f0f11d8a7448e3f4ec405c29c3d18d7a1d6f
6
+ metadata.gz: 985bd27768d1256eec6b4f1c9dff4da974e6d52e6163da4dd90b9e48416042412dfff300ae1aabec922e45274799204a6bfd3e056f84946caa1650b32189face
7
+ data.tar.gz: d7ef3483025caa62727ca4eacce1be7300aee79ad1d428c5682985c666150e60c69c3d9d855b93da4b9e16bd5af883a7dbd2bc56d29ce4e11fec3494f248821d
data/README.md CHANGED
@@ -115,12 +115,51 @@ Note that `each_serializer` and `serializer` is not part of `SkinnyControllers`,
115
115
 
116
116
  Also note that setting `model_class` may be required if your model is namespaced.
117
117
 
118
- #### parent_class
118
+ #### parent_class and association_name
119
119
 
120
- #### association_name
120
+ If you want to scope the finding of a resource to a parent object, `parent_class` must be set
121
+
122
+ ```ruby
123
+ skinny_controllers_config parent_class: ParentClass,
124
+ assaciation_name: :children,
125
+ model_class: Child
126
+ ```
127
+
128
+ Given the above configuration in a controller, and a request with the params:
129
+
130
+ ```
131
+ {
132
+ id: 2,
133
+ parent_id: 78
134
+ }
135
+ ```
136
+
137
+ The following query will be made:
138
+
139
+ ```ruby
140
+ Parent.find(78).children.find(2)
141
+ ```
121
142
 
122
143
  #### model_params_key
123
144
 
145
+ Date stored another a different key in `params`?
146
+
147
+ ```ruby
148
+ skinny_controllers_config model_class: Child,
149
+ model_params_key: :progeny
150
+ ```
151
+
152
+ Given the above configuration in a controller, and a request with the params:
153
+
154
+ ```
155
+ {
156
+ progeny: {
157
+ attribute1: 'value'
158
+ }
159
+ }
160
+ ```
161
+
162
+ The attributes inside the `progeny` sub hash will be used instead of the default, `child`.
124
163
 
125
164
  ### What if your model is namespaced?
126
165
 
@@ -129,8 +168,9 @@ All you have to do is set the `model_class`, and `model_key`.
129
168
  ```ruby
130
169
  class ItemsController < ApiController # or whatever your superclass is
131
170
  include SkinnyControllers::Diet
132
- self.model_class = NameSpace::Item
133
- self.model_key = 'item'
171
+
172
+ skinny_controllers_config model_class: NameSpace::Item
173
+ model_params_key: :item
134
174
  end
135
175
  ```
136
176
  `model_key` specifies the key to look for params when creating / updating the model.
@@ -230,7 +270,7 @@ To achieve default functionality, this operation *may* be defined -- though, it
230
270
  module UserOperations
231
271
  class Create < SkinnyControllers::Operation::Base
232
272
  def run
233
- @model = model_class.new(model_params)
273
+ @model = User.new(model_params)
234
274
 
235
275
  # raising an exception here allows the corresponding resource controller to
236
276
  # `rescue_from SkinnyControllers::DeniedByPolicy` and have a uniform error
@@ -294,6 +334,15 @@ end
294
334
 
295
335
  These are snippets taking from other projects.
296
336
 
337
+ ### Using ransack
338
+
339
+ ```ruby
340
+ # config/initializers/skinny_controllers.rb
341
+ SkinnyControllers.search_proc = lambda do |relation|
342
+ relation.ransack(params[:q]).result
343
+ end
344
+ ```
345
+
297
346
  ### Finding a record when the id parameter isn't passed
298
347
 
299
348
  ```ruby
@@ -483,6 +532,7 @@ The following options are available:
483
532
  |`controller_namespace`|`''`| Global Namespace for all controllers (e.g.: `'API'`) |
484
533
  |`allow_by_default`| `true` | Default permission |
485
534
  |`action_map`| see [skinny_controllers.rb](./lib/skinny_controllers.rb#L61)| |
535
+ | `search_proc`| passthrough | can be used to filter results, such as with using ransack |
486
536
 
487
537
 
488
538
  -------------------------------------------------------
@@ -86,7 +86,7 @@ module SkinnyControllers
86
86
  name = name.camelize
87
87
  association = model_from_scope(id: id, type: name)
88
88
 
89
- SkinnyControllers.search_proc.call(association)
89
+ instance_exec(association, &SkinnyControllers.search_proc)
90
90
  end
91
91
 
92
92
  def model_from_scope(scope = params[:scope])
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SkinnyControllers
3
- VERSION = '0.10.0'
3
+ VERSION = '0.10.1'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skinny_controllers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - L. Preston Sego III
@@ -238,6 +238,6 @@ rubyforge_project:
238
238
  rubygems_version: 2.5.1
239
239
  signing_key:
240
240
  specification_version: 4
241
- summary: SkinnyControllers-0.10.0
241
+ summary: SkinnyControllers-0.10.1
242
242
  test_files: []
243
243
  has_rdoc: