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 +4 -4
- data/README.md +55 -5
- data/lib/skinny_controllers/operation/model_helpers.rb +1 -1
- data/lib/skinny_controllers/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d020916e740eec6d6047321f6797499deedd91a9
|
4
|
+
data.tar.gz: 38f090da8386787f87ceaaa58ab37e6b8653cd38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
133
|
-
|
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 =
|
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
|
89
|
+
instance_exec(association, &SkinnyControllers.search_proc)
|
90
90
|
end
|
91
91
|
|
92
92
|
def model_from_scope(scope = params[:scope])
|
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.
|
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.
|
241
|
+
summary: SkinnyControllers-0.10.1
|
242
242
|
test_files: []
|
243
243
|
has_rdoc:
|