skinny_controllers 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -5
- data/lib/skinny_controllers/diet.rb +31 -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: 9735ef5cd26ccd5b7d38ceb77c75f75d3452fa6d
|
4
|
+
data.tar.gz: 08eb8e5328cfaedd10e77572c98e6ca8ba4affcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 975a53f3c9430fe8768249c12d4d15af63d8bce50acde081443566f8bba6a87b3a46e18a2a4d889e792c94be97d2bcf310cbb1f24247e56f3893416cae2e7ca3
|
7
|
+
data.tar.gz: e3bb637259fcea7c5c137e61294ca5e009d08597a5185e340fd6e13f7241d620dc0852fb2d4aed8b5eae44bc25938032919f2a1710816c6770cd30b76757a83a
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# skinny-controllers
|
2
|
-
[![Gem Version](
|
3
|
-
[![Build Status](
|
4
|
-
[![Code Climate](
|
5
|
-
[![Test Coverage](
|
6
|
-
[![
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/skinny_controllers.svg)](https://badge.fury.io/rb/skinny_controllers)
|
3
|
+
[![Build Status](https://travis-ci.org/NullVoxPopuli/skinny_controllers.svg?branch=master)](https://travis-ci.org/NullVoxPopuli/skinny_controllers)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/NullVoxPopuli/skinny_controllers/badges/gpa.svg)](https://codeclimate.com/github/NullVoxPopuli/skinny_controllers)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/NullVoxPopuli/skinny_controllers/badges/coverage.svg)](https://codeclimate.com/github/NullVoxPopuli/skinny_controllers/coverage)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/skinny_controllers.svg)](https://badge.fury.io/rb/skinny_controllers)
|
7
7
|
|
8
8
|
An implementation of role-based policies and operations to help controllers lose weight.
|
9
9
|
|
@@ -44,6 +44,7 @@ The above does a multitude of assumptions to make sure that you can type the lea
|
|
44
44
|
3. Your model responds to `find`, and `where`
|
45
45
|
4. Your model responds to `is_accessible_to?`. This can be changed at `SkinnyControllers.accessible_to_method`
|
46
46
|
5. If relying on the default / implicit operations for create and update, the params key for your model's changes much be formatted as `{ Model.name.underscore => { attributes }}``
|
47
|
+
6. If using strong parameters, SkinnyControllers will look for `{action}_{model}_params` then `{model}_params` and then `params`. See the `strong_parameters_spec.rb` test to see an example.
|
47
48
|
|
48
49
|
### Your model name might be different from your resource name
|
49
50
|
Lets say you have a JSON API resource that you'd like to render that has some additional/subset of data.
|
@@ -10,7 +10,7 @@ module SkinnyControllers
|
|
10
10
|
#
|
11
11
|
# @return an instance of the operation with default parameters
|
12
12
|
def operation
|
13
|
-
@operation ||= operation_class.new(current_user,
|
13
|
+
@operation ||= operation_class.new(current_user, params_for_action)
|
14
14
|
end
|
15
15
|
|
16
16
|
# Assumes the operation name from the controller name
|
@@ -33,6 +33,36 @@ module SkinnyControllers
|
|
33
33
|
|
34
34
|
private
|
35
35
|
|
36
|
+
# In order of most specific, to least specific:
|
37
|
+
# - {action}_{model_name}_params
|
38
|
+
# - {model_name}_params
|
39
|
+
# - params
|
40
|
+
#
|
41
|
+
# It's recommended to use whitelisted strong parameters on
|
42
|
+
# actions such as create and update
|
43
|
+
#
|
44
|
+
# @return the whitelisted strong parameters object
|
45
|
+
def params_for_action
|
46
|
+
model_key =
|
47
|
+
if model_class
|
48
|
+
# model_class should be a class
|
49
|
+
model_class.name.underscore
|
50
|
+
else
|
51
|
+
Lookup::Controller.model_name(self.class.name).underscore
|
52
|
+
end
|
53
|
+
|
54
|
+
action_params_method = "#{action_name}_#{model_key}_params"
|
55
|
+
model_params_method = "#{model_key}_params"
|
56
|
+
|
57
|
+
if respond_to? action_params_method
|
58
|
+
send(action_params_method)
|
59
|
+
elsif respond_to? model_params_method
|
60
|
+
send(model_params_method)
|
61
|
+
else
|
62
|
+
params
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
36
66
|
# action name is inherited from ActionController::Base
|
37
67
|
# http://www.rubydoc.info/docs/rails/2.3.8/ActionController%2FBase%3Aaction_name
|
38
68
|
def verb_for_action
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- L. Preston Sego III
|
@@ -224,5 +224,5 @@ rubyforge_project:
|
|
224
224
|
rubygems_version: 2.4.8
|
225
225
|
signing_key:
|
226
226
|
specification_version: 4
|
227
|
-
summary: SkinnyControllers-0.
|
227
|
+
summary: SkinnyControllers-0.5.0
|
228
228
|
test_files: []
|