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: 26706470796dde22b48898b13687712bcca34bc2
4
- data.tar.gz: 970870851726f042d3fb8f1739186f71b7b0b906
3
+ metadata.gz: 15c86aa2d14544c566cb2ef4761a606a7c0037dc
4
+ data.tar.gz: 1a0f4d3b18b566e0c472403d53e8bf6d3b009be7
5
5
  SHA512:
6
- metadata.gz: 3482e3d9ce1ebe753904bd4917573e9382f51c586bcc12b0a38d81dda33d6c2b455ac3b03943df2e9898f2d76514c20d0c91a8baa0d14b19ae5fd4abd7db5fa9
7
- data.tar.gz: e9d4fb829b0b4e1473ee186a5f9b25d8eda214e90519a419501904b65f8587167c4b6c5817297c8b6296004a9b5cd97502d07d52cf5b164aa11c6dcc86562aa8
6
+ metadata.gz: b31031668f0ea82c889a0c8cc84280f027c95f0c683c6fa112775cc665d9ce5b7c8b2a2428da738174e6c706d6cc5a13746f1b65251ee8aa53b6615ca1a16f4c
7
+ data.tar.gz: 9abf84595952ea832fcca40f88ca17767344d0d00b2fa26da32543133b4638fa8b3f8a1a28d5422994c94c8663a5281131df298ff63ef2d5f0816b0a064d351e
@@ -4,7 +4,7 @@ module SkinnyControllers
4
4
  # An example Operation may looy like
5
5
  #
6
6
  # module EventOperations
7
- # class Read < SkinnyControllers::Policy::Base
7
+ # class Read < SkinnyControllers::Operation::Base
8
8
  # def run
9
9
  # model if allowed?
10
10
  # end
@@ -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
- if params[:scope]
9
- model_from_scope
10
- elsif (key = params.keys.grep(/\_id$/)).present?
11
- # hopefully there is only ever one of these passed
12
- id = params[key.first]
13
- model_from_named_id(key.first, id)
14
- elsif id_from_params
15
- model_from_id
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
- model_from_params
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
@@ -1,3 +1,3 @@
1
1
  module SkinnyControllers
2
- VERSION = '0.5.9'
2
+ VERSION = '0.6.0'
3
3
  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.5.9
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: 2015-12-18 00:00:00.000000000 Z
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.5.9
227
+ summary: SkinnyControllers-0.6.0
228
228
  test_files: []
229
+ has_rdoc: