singular_resource 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bbe80e9d964d0c6282349575f5ed7dfe2e01bf1
|
4
|
+
data.tar.gz: b28fe3571f97ed496ebbd2a893d74656fe81c9e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e00ff4e8ae2fb027d2ff1552f724040427212aeb9a748d5b6765a341ce655db739c8847780c224aebfb3af6dfc27e47037378346172cdf18cec40a3daecda6b
|
7
|
+
data.tar.gz: 4a39801a4abe1a42a6d6df690be40fe3b847ebae3e984963022a436e125021866802666ad5f9b450c4cf6c76f718a672bdc19f1915902046e9954231c2045c5e
|
data/README.md
CHANGED
@@ -12,9 +12,18 @@ Expose the model in any way, scope the query to a collection method if defined,
|
|
12
12
|
|
13
13
|
|
14
14
|
## Use
|
15
|
-
It provides a private method that performs a query for the document when invoked
|
15
|
+
It provides a private method that performs a query for the document when invoked whenever id is defined.
|
16
|
+
When there is no id parameter, like in `new` and `create`, it returns an initialized model.
|
16
17
|
```ruby
|
17
|
-
|
18
|
+
# app/controllers/person_controller.rb
|
19
|
+
class PersonController < ApplicationController
|
20
|
+
singular_resource :person
|
21
|
+
|
22
|
+
def destroy
|
23
|
+
person.destroy
|
24
|
+
redirect_to action: :index
|
25
|
+
end
|
26
|
+
end
|
18
27
|
```
|
19
28
|
|
20
29
|
#### Strategies
|
@@ -23,15 +32,15 @@ By default, it uses `StrongParametersStrategy`, which only assigns the attribute
|
|
23
32
|
|
24
33
|
#### Options
|
25
34
|
``` ruby
|
26
|
-
|
35
|
+
optional: "Return nil if the document does not exist when passed a truthy value",
|
27
36
|
|
28
|
-
|
37
|
+
model: "Class or name of the model class",
|
29
38
|
|
30
|
-
:
|
39
|
+
finder_parameter: "Name of the parameter that has the document's id",
|
31
40
|
|
32
|
-
|
41
|
+
attributes: "Name of the attributes method name if using strong parameters",
|
33
42
|
|
34
|
-
|
43
|
+
param_key: "Name of the parameter that has the document's attributes"
|
35
44
|
```
|
36
45
|
|
37
46
|
## Comparison
|
@@ -158,7 +167,7 @@ class Controller
|
|
158
167
|
end
|
159
168
|
```
|
160
169
|
|
161
|
-
If you think that the `before_filter` is nasty or don't like ivars in your views, so do I! Check the [
|
170
|
+
If you think that the `before_filter` is nasty or don't like ivars in your views, so do I! Check the [presenter_rails](http://github.com/ElMassimo/presenter_rails) gem
|
162
171
|
|
163
172
|
### Special Thanks
|
164
173
|
Singular Resource is a subset of [decent_exposure](https://github.com/voxdolo/decent_exposure).
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'singular_resource/strategies/assign_attributes'
|
2
|
+
|
3
|
+
module SingularResource
|
4
|
+
module Strategies
|
5
|
+
module AssignFromMethodEager
|
6
|
+
include AssignAttributes
|
7
|
+
|
8
|
+
def attributes
|
9
|
+
@attributes ||= method_attributes || {}
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def default_params_method
|
15
|
+
"#{name}_params"
|
16
|
+
end
|
17
|
+
|
18
|
+
def method_attributes
|
19
|
+
controller.send(options[:attributes] || default_params_method) unless options[:attributes] == false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'singular_resource/strategies/mongoid_strategy'
|
2
|
-
require 'singular_resource/strategies/
|
2
|
+
require 'singular_resource/strategies/assign_from_method_eager'
|
3
3
|
|
4
4
|
module SingularResource
|
5
5
|
module Strategies
|
6
6
|
class StrongParametersStrategy < MongoidStrategy
|
7
|
-
include Strategies::
|
7
|
+
include Strategies::AssignFromMethodEager
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: singular_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Máximo Mussini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/singular_resource/resource.rb
|
58
58
|
- lib/singular_resource/strategies/assign_attributes.rb
|
59
59
|
- lib/singular_resource/strategies/assign_from_method.rb
|
60
|
+
- lib/singular_resource/strategies/assign_from_method_eager.rb
|
60
61
|
- lib/singular_resource/strategies/assign_from_params.rb
|
61
62
|
- lib/singular_resource/strategies/eager_attributes_strategy.rb
|
62
63
|
- lib/singular_resource/strategies/mongoid_strategy.rb
|