skinny_controllers 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -6
- data/lib/skinny_controllers/diet.rb +14 -9
- data/lib/skinny_controllers/lookup/operation.rb +0 -2
- data/lib/skinny_controllers/lookup/policy.rb +2 -2
- data/lib/skinny_controllers/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a12f7c66cb3fb07308f8aa6ab246be35b70831e7
|
4
|
+
data.tar.gz: 6e6acbd5421a2da92d57c3db2ac144f2eae343b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbd2f49c04417e59e35c426c537da234608b93ce4c58fa7609c6b1b786f9bf734d710eaacf7120207640325b9d3d61f66596cb1f4787760bb9c962a746b0df5d
|
7
|
+
data.tar.gz: 9ca0a73f862a34887ecd528efb4cf62ba6b5615e26a374b8462c9681003ca6b99018df0129367c185063cbe50c43f67869f102d0458de2294d563ad6df3da932
|
data/README.md
CHANGED
@@ -9,9 +9,7 @@ An implementation of role-based policies and operations to help controllers lose
|
|
9
9
|
|
10
10
|
The goal of this project is to help API apps be more slim, and separate logic as much as possible.
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
Please note that this is a work in progress, and that the defaults are subject to change. If you have an idea or suggestion for improved defaults, please submit an issue or pull request. :-)
|
12
|
+
If you have an idea or suggestion for improved defaults, please submit an issue or pull request. :-)
|
15
13
|
|
16
14
|
# Installation
|
17
15
|
|
@@ -110,6 +108,16 @@ def host_params
|
|
110
108
|
end
|
111
109
|
```
|
112
110
|
|
111
|
+
The parameters for directly calling an operation are as follows:
|
112
|
+
|
113
|
+
| # | Parameter | Default when directly calling an operation | Implicit default via `model` | Purpose |
|
114
|
+
|---|-------------------|--------------------------------------------|------------------------------|------------------------------------------|
|
115
|
+
| 0 | current_user | n/a | `current_user` | the user performing the action |
|
116
|
+
| 1 | controller_params | n/a | `params` | the full params hash from the controller |
|
117
|
+
| 2 | params_for_action | `controller_params` | `create_params`, `index_params`, etc | e.g.: requiring a foreign key when looking up index |
|
118
|
+
| 3 | action | `controller_params[:action]` | `action_name` | the name of the current action |
|
119
|
+
| 4 | model_key | `nil` | underscored model class name | the underscored model class name |
|
120
|
+
|
113
121
|
### For JSON-API
|
114
122
|
|
115
123
|
Strong parameters must be used on create/update actions.
|
@@ -255,7 +263,18 @@ The following options are available:
|
|
255
263
|
|`accessible_to_scope`| `accessible_to`| scope / class method on an object that the user might be able to access |
|
256
264
|
|`action_map`| see [skinny_controllers.rb](./lib/skinny_controllers.rb#L61)| |
|
257
265
|
|
258
|
-
## TODO
|
259
266
|
|
260
|
-
|
261
|
-
|
267
|
+
-------------------------------------------------------
|
268
|
+
|
269
|
+
## How is this different from trailblazer?
|
270
|
+
|
271
|
+
This may not be horribly apparent, but here is a table overviewing some highlevel differences
|
272
|
+
|
273
|
+
| Feature | - | skinny_controllers | [trailblazer](https://github.com/apotonick/trailblazer) |
|
274
|
+
|--|--|--|--|
|
275
|
+
| Purpose |-| API - works very well with [ActiveModel::Serializers](https://github.com/rails-api/active_model_serializers)| General - additional featers for server-side rendered views |
|
276
|
+
| Added Layers |-| Operations, Policies | Operations, Policies, Forms |
|
277
|
+
| Validation |-| stay in models | moved to operations via contract block |
|
278
|
+
| Additional objects| -| none | contacts, representers, callbacks, cells |
|
279
|
+
| Rendering | -| done in the controller, and up to the dev to decide how that is done. `ActiveModel::Serializers` with JSON-API is highly recommended | representers provide a way to define serializers for json, xml, json-api, etc |
|
280
|
+
| App Structure | - | same as rails. `app/operations` and `app/policies` are added | encourages a new structure 'concepts', where cells, view templates, assets, operations, etc are all under `concepts/{model-name}` |
|
@@ -3,8 +3,10 @@ module SkinnyControllers
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
|
7
|
-
|
6
|
+
class << self
|
7
|
+
attr_accessor :model_class
|
8
|
+
attr_accessor :model_key
|
9
|
+
end
|
8
10
|
end
|
9
11
|
|
10
12
|
# TODO: what if we want multiple operations per action?
|
@@ -14,7 +16,7 @@ module SkinnyControllers
|
|
14
16
|
@operation ||= operation_class.new(
|
15
17
|
current_user,
|
16
18
|
params, params_for_action,
|
17
|
-
action_name, model_key)
|
19
|
+
action_name, self.class.model_key)
|
18
20
|
end
|
19
21
|
|
20
22
|
# Assumes the operation name from the controller name
|
@@ -22,7 +24,7 @@ module SkinnyControllers
|
|
22
24
|
# @example SomeObjectsController => Operation::SomeObject::Action
|
23
25
|
# @return [Class] the operation class for the model and verb
|
24
26
|
def operation_class
|
25
|
-
Lookup::Operation.from_controller(self.class.name, verb_for_action, model_class)
|
27
|
+
Lookup::Operation.from_controller(self.class.name, verb_for_action, self.class.model_class)
|
26
28
|
end
|
27
29
|
|
28
30
|
# abstraction for `operation.run`
|
@@ -49,12 +51,15 @@ module SkinnyControllers
|
|
49
51
|
def params_for_action
|
50
52
|
return {} if action_name == 'destroy'
|
51
53
|
|
54
|
+
key = self.class.model_key
|
55
|
+
# model_class should be a class
|
56
|
+
klass = self.class.model_class
|
57
|
+
|
52
58
|
model_key =
|
53
|
-
if
|
54
|
-
|
55
|
-
elsif
|
56
|
-
|
57
|
-
model_class.name.underscore
|
59
|
+
if key.present?
|
60
|
+
key
|
61
|
+
elsif klass
|
62
|
+
klass.name.underscore
|
58
63
|
else
|
59
64
|
Lookup::Controller.model_name(self.class.name).underscore
|
60
65
|
end
|
@@ -20,11 +20,11 @@ module SkinnyControllers
|
|
20
20
|
default_policy = SkinnyControllers::Policy::Default
|
21
21
|
namespace_klass = Object
|
22
22
|
# if we are namespaced, we need to get / create the namespace if it doesn't exist already
|
23
|
-
if
|
23
|
+
if name.include?('::')
|
24
24
|
namespaces = name.split('::')
|
25
25
|
namespace = namespaces[0..-2].join('::').presence
|
26
26
|
namespace = namespace == name ? 'Object' : namespace
|
27
|
-
if
|
27
|
+
if namespace.presence && namespace != name
|
28
28
|
namespace_klass = Namespace.create_namespace(namespace)
|
29
29
|
end
|
30
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skinny_controllers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- L. Preston Sego III
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -222,8 +222,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
222
|
version: '0'
|
223
223
|
requirements: []
|
224
224
|
rubyforge_project:
|
225
|
-
rubygems_version: 2.
|
225
|
+
rubygems_version: 2.5.1
|
226
226
|
signing_key:
|
227
227
|
specification_version: 4
|
228
|
-
summary: SkinnyControllers-0.7.
|
228
|
+
summary: SkinnyControllers-0.7.3
|
229
229
|
test_files: []
|