skinny_controllers 0.5.1 → 0.5.2
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 +23 -0
- data/lib/skinny_controllers/operation/base.rb +7 -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: f2e1ec3f77c39858d0b820f251510b79bcc3e4d2
|
4
|
+
data.tar.gz: f3248c60ec78d9f32994db937966180d4c423a9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06f7c1e5f83f884cf011db58efa12c09043483f7fbb506e67bd02758a711b93e54e5a3f1ea5aaf50fd38b306be080fe5b1e9e41c2e3e95268bba7700b5e6f258
|
7
|
+
data.tar.gz: 35b555b099adb1ba915cc88da1c1f62b289de0aacdb6d8a0dea9e923462a992f6efaf0c5b554d9c357187e08b8ef8a0cfc7498ee5e7072b70f9fdf4196940e28
|
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
[](https://travis-ci.org/NullVoxPopuli/skinny_controllers)
|
4
4
|
[](https://codeclimate.com/github/NullVoxPopuli/skinny_controllers)
|
5
5
|
[](https://codeclimate.com/github/NullVoxPopuli/skinny_controllers/coverage)
|
6
|
+
[](https://gemnasium.com/NullVoxPopuli/skinny_controllers)
|
6
7
|
|
7
8
|
An implementation of role-based policies and operations to help controllers lose weight.
|
8
9
|
|
@@ -72,6 +73,28 @@ end
|
|
72
73
|
```
|
73
74
|
Note that `each_serializer` and `serializer` is not part of `SkinnyControllers`, and is part of [ActiveModel::Serializers](https://github.com/rails-api/active_model_serializers).
|
74
75
|
|
76
|
+
|
77
|
+
### What if you want to call your own operations?
|
78
|
+
|
79
|
+
Sometimes, magic is scary. You can call anything you want manually (operations and policies).
|
80
|
+
|
81
|
+
Here is an example that manually makes the call to the Host Operations and passes the subdomain parameter in to filter the `Host` object on the subdomain.
|
82
|
+
```ruby
|
83
|
+
def show
|
84
|
+
render json: host_from_subdomain, serializer: each_serializer
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def host_from_subdomain
|
90
|
+
@host ||= HostOperations::Read.new(current_user, host_params).run
|
91
|
+
end
|
92
|
+
|
93
|
+
def host_params
|
94
|
+
params.permit(:subdomain)
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
75
98
|
## Defining Operations
|
76
99
|
|
77
100
|
Operations should be placed in `app/operations` of your rails app.
|
@@ -62,7 +62,13 @@ module SkinnyControllers
|
|
62
62
|
#
|
63
63
|
# @example Operation::Event::Read would become read?
|
64
64
|
def policy_method_name
|
65
|
-
@policy_method_name
|
65
|
+
unless @policy_method_name
|
66
|
+
method = Lookup::Policy.method_name_for_operation(self.class.name)
|
67
|
+
has_method = policy_class.instance_methods.include?(method.to_sym)
|
68
|
+
@policy_method_name = has_method ? method : 'default?'
|
69
|
+
end
|
70
|
+
|
71
|
+
@policy_method_name
|
66
72
|
end
|
67
73
|
|
68
74
|
# @return a new policy object and caches it
|
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.5.
|
4
|
+
version: 0.5.2
|
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.5.
|
227
|
+
summary: SkinnyControllers-0.5.2
|
228
228
|
test_files: []
|