skinny_controllers 0.4.0 → 0.5.0

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: 52131d9a1e993b5046ea0104928cce55b32cfa8e
4
- data.tar.gz: dbcc1157c9129361df79a71b2f8e5c103a9d94e0
3
+ metadata.gz: 9735ef5cd26ccd5b7d38ceb77c75f75d3452fa6d
4
+ data.tar.gz: 08eb8e5328cfaedd10e77572c98e6ca8ba4affcd
5
5
  SHA512:
6
- metadata.gz: 77aa4ae8568318784f6092a5d8f109f726a2a53134e5217ffe0b18ca1ab31bd63c81121ed62ca58c632f716221b587606a40b510768fd9c2d7743cb56307f51a
7
- data.tar.gz: 968f986aa8a475bd965df72c49252b5c073466cca3b8a59d2b68293da93275c3b17c0a85fbb1bdfe49fcdf11d433d08a6c7f39a69027c607e3c390eb918797a6
6
+ metadata.gz: 975a53f3c9430fe8768249c12d4d15af63d8bce50acde081443566f8bba6a87b3a46e18a2a4d889e792c94be97d2bcf310cbb1f24247e56f3893416cae2e7ca3
7
+ data.tar.gz: e3bb637259fcea7c5c137e61294ca5e009d08597a5185e340fd6e13f7241d620dc0852fb2d4aed8b5eae44bc25938032919f2a1710816c6770cd30b76757a83a
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # skinny-controllers
2
- [![Gem Version](http://img.shields.io/gem/v/skinny_controllers.svg?style=flat-square)](http://badge.fury.io/rb/skinny_controllers)
3
- [![Build Status](http://img.shields.io/travis/NullVoxPopuli/skinny_controllers.svg?style=flat-square)](https://travis-ci.org/NullVoxPopuli/skinny_controllers)
4
- [![Code Climate](http://img.shields.io/codeclimate/github/NullVoxPopuli/skinny_controllers.svg?style=flat-square)](https://codeclimate.com/github/NullVoxPopuli/skinny_controllers)
5
- [![Test Coverage](http://img.shields.io/codeclimate/coverage/github/NullVoxPopuli/skinny_controllers.svg?style=flat-square)](https://codeclimate.com/github/NullVoxPopuli/skinny_controllers)
6
- [![Dependency Status](http://img.shields.io/gemnasium/NullVoxPopuli/skinny_controllers.svg?style=flat-square)](https://gemnasium.com/NullVoxPopuli/skinny_controllers)
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, params)
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
@@ -1,3 +1,3 @@
1
1
  module SkinnyControllers
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  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.4.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.4.0
227
+ summary: SkinnyControllers-0.5.0
228
228
  test_files: []