skinny_controllers 0.8.0 → 0.8.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 +48 -0
- data/lib/skinny_controllers/operation/model_helpers.rb +1 -1
- data/lib/skinny_controllers/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfc833504dfcb98816addf70327d77fc5b226266
|
4
|
+
data.tar.gz: c8f44f79873234d5aa2c7cd0cd0a802ed30ae8f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2af0e8182e1a556fbc990ad30d7f7b564772b2b89877f6d5b46470e870d6389f0ce5320a028ae2c511e63d7b6ca22daa94126ee3d11cf5dea7cd1fc6df59c18
|
7
|
+
data.tar.gz: fe8314a6a8bb42d93df89b57c71127ec4d024012ab7352fc8998f1677800a60e2013ef17a0e57e0da24212d280406b4b5b2b66877a025f1af0858845ccc6d40a
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# skinny_controllers
|
2
2
|
|
3
|
+
_skinny_controllers is a thin layer on top of rails with the goal of allowing for much easier unit-testability, inspired by ember_
|
4
|
+
|
5
|
+
A demo app can be found [in the spec here](https://github.com/NullVoxPopuli/skinny_controllers/tree/master/spec/support/rails_app).
|
6
|
+
|
3
7
|
[](https://gitter.im/NullVoxPopuli/skinny_controllers?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
8
|
[](https://badge.fury.io/rb/skinny_controllers)
|
5
9
|
[](https://travis-ci.org/NullVoxPopuli/skinny_controllers)
|
@@ -13,6 +17,16 @@ The goal of this project is to help API apps be more slim, and separate logic as
|
|
13
17
|
|
14
18
|
If you have an idea or suggestion for improved defaults, please submit an issue or pull request. :-)
|
15
19
|
|
20
|
+
# Overview
|
21
|
+
|
22
|
+
- Controllers _only_ contain render logic. Typically, `render json: model`
|
23
|
+
- Business logic is encapsulated in operations.
|
24
|
+
- Without creating any new classes, `render json: model` will give you default CRUD functionality in your controller actions.
|
25
|
+
- There is one operation per controller action.
|
26
|
+
- Policies help determine whether or not the `current_user` is allowed to perform an action on an object.
|
27
|
+
- [Click here to see how this is different from trailblazer](https://github.com/NullVoxPopuli/skinny_controllers#how-is-this-different-from-trailblazer)
|
28
|
+
|
29
|
+
|
16
30
|
# Installation
|
17
31
|
|
18
32
|
```ruby
|
@@ -331,6 +345,40 @@ module MembershipRenewalOperations
|
|
331
345
|
end
|
332
346
|
```
|
333
347
|
|
348
|
+
### Updating / Deleting the current_user
|
349
|
+
|
350
|
+
This is something you could do if you always know your model ahead of time.
|
351
|
+
|
352
|
+
```ruby
|
353
|
+
module UserOperations
|
354
|
+
class Update < SkinnyControllers::Operation::Base
|
355
|
+
def run
|
356
|
+
return unless allowed_for?(current_user)
|
357
|
+
current_user.update_with_password(model_params)
|
358
|
+
current_user
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
class Delete < SkinnyControllers::Operation::Base
|
363
|
+
def run
|
364
|
+
if allowed_for?(current_user)
|
365
|
+
if current_user.upcoming_events.count > 0
|
366
|
+
current_user.errors.add(
|
367
|
+
:base,
|
368
|
+
"You cannot delete your account when you are about to attend an event."
|
369
|
+
)
|
370
|
+
else
|
371
|
+
current_user.destroy
|
372
|
+
end
|
373
|
+
|
374
|
+
current_user
|
375
|
+
end
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
end
|
380
|
+
```
|
381
|
+
|
334
382
|
## Testing
|
335
383
|
|
336
384
|
The whole goal of this project is to minimize the complexity or existence of controller tests, and provide
|
@@ -95,7 +95,7 @@ module SkinnyControllers
|
|
95
95
|
association = association_name_from_object
|
96
96
|
scoped.send(association)
|
97
97
|
else
|
98
|
-
raise "Parent object of type #{scope[:type]} not accessible"
|
98
|
+
raise ActiveRecord::RecordNotFound, "Parent object of type #{scope[:type]} not accessible"
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
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.8.
|
4
|
+
version: 0.8.1
|
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-
|
11
|
+
date: 2016-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -231,8 +231,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
231
231
|
version: '0'
|
232
232
|
requirements: []
|
233
233
|
rubyforge_project:
|
234
|
-
rubygems_version: 2.
|
234
|
+
rubygems_version: 2.5.1
|
235
235
|
signing_key:
|
236
236
|
specification_version: 4
|
237
|
-
summary: SkinnyControllers-0.8.
|
237
|
+
summary: SkinnyControllers-0.8.1
|
238
238
|
test_files: []
|
239
|
+
has_rdoc:
|