skinny_controllers 0.5.9 → 0.6.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15c86aa2d14544c566cb2ef4761a606a7c0037dc
|
4
|
+
data.tar.gz: 1a0f4d3b18b566e0c472403d53e8bf6d3b009be7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b31031668f0ea82c889a0c8cc84280f027c95f0c683c6fa112775cc665d9ce5b7c8b2a2428da738174e6c706d6cc5a13746f1b65251ee8aa53b6615ca1a16f4c
|
7
|
+
data.tar.gz: 9abf84595952ea832fcca40f88ca17767344d0d00b2fa26da32543133b4638fa8b3f8a1a28d5422994c94c8663a5281131df298ff63ef2d5f0816b0a064d351e
|
@@ -4,18 +4,29 @@ module SkinnyControllers
|
|
4
4
|
def model
|
5
5
|
# TODO: not sure if multiple ids is a good idea here
|
6
6
|
# if we don't have a(ny) id(s), get all of them
|
7
|
-
@model ||=
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
@model ||= find_model
|
8
|
+
end
|
9
|
+
|
10
|
+
# hopefully this method is only ever called once per request
|
11
|
+
# via the memoization in #model
|
12
|
+
def find_model
|
13
|
+
if params[:scope]
|
14
|
+
model_from_scope
|
15
|
+
elsif (key = params.keys.grep(/\_id$/)).present?
|
16
|
+
# hopefully there is only ever one of these passed
|
17
|
+
id = params[key.first]
|
18
|
+
if params['id'].present?
|
19
|
+
# single item / show
|
20
|
+
model_from_parent(key.first, id, params['id'])
|
16
21
|
else
|
17
|
-
|
22
|
+
# list of items / index
|
23
|
+
model_from_named_id(key.first, id)
|
18
24
|
end
|
25
|
+
elsif id_from_params
|
26
|
+
model_from_id
|
27
|
+
else
|
28
|
+
model_from_params
|
29
|
+
end
|
19
30
|
end
|
20
31
|
|
21
32
|
def sanitized_params
|
@@ -41,6 +52,9 @@ module SkinnyControllers
|
|
41
52
|
model_name.underscore
|
42
53
|
end
|
43
54
|
|
55
|
+
# @param [Hash] scoped_params
|
56
|
+
# @option scoped_params :type the class name
|
57
|
+
# @option scoped_params :id the id of the class to look up
|
44
58
|
def scoped_model(scoped_params)
|
45
59
|
unless @scoped_model
|
46
60
|
klass_name = scoped_params[:type]
|
@@ -84,6 +98,11 @@ module SkinnyControllers
|
|
84
98
|
end
|
85
99
|
end
|
86
100
|
|
101
|
+
def model_from_parent(parent_class, parent_id, id)
|
102
|
+
association = model_from_named_id(parent_class, parent_id)
|
103
|
+
association.find(id)
|
104
|
+
end
|
105
|
+
|
87
106
|
def model_from_id
|
88
107
|
model_class.find(id_from_params)
|
89
108
|
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.
|
4
|
+
version: 0.6.0
|
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:
|
11
|
+
date: 2016-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -224,5 +224,6 @@ rubyforge_project:
|
|
224
224
|
rubygems_version: 2.4.8
|
225
225
|
signing_key:
|
226
226
|
specification_version: 4
|
227
|
-
summary: SkinnyControllers-0.
|
227
|
+
summary: SkinnyControllers-0.6.0
|
228
228
|
test_files: []
|
229
|
+
has_rdoc:
|