rails-rapido 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -6
- data/lib/rapido/api_controller.rb +2 -1
- data/lib/rapido/controller.rb +6 -1
- data/lib/rapido/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c7123a3a6f6a4c588644079e1aa18d1f2f43f65fba2a073bdf65ad5d969f84f
|
4
|
+
data.tar.gz: 06b29712f5d93a0121b71a6f5af810cdbf9c3869049a202a2f5923f8333743f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bad24cf889ce9d2fda165b50850a60b7b2bcb8a38800d8224027d1b9efd8fc68e2584a3b6e5356604437f4d6587568ec33b7bc7270f71e95801a1a6f2115bdd7
|
7
|
+
data.tar.gz: 3af33765a75abeb4b7abf4c9ba4ada1dc1d0190fae2f45fa2af2b48ba6d8b15b7a4b0e607e70f54549d24b88017151cf58e14e5180a0615d24a47075dee4077f
|
data/README.md
CHANGED
@@ -54,18 +54,20 @@ Specifies the param used to retrieve the resource. For example, if `Post` belong
|
|
54
54
|
|
55
55
|
Specifies the class that will present the resource. This class must accept the resource as the only parameter at initialization, and respond to the `as_json` for output when used with the `Rapido::ApiController`.
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
Specifies the class that will present a collection of resources, as in the index method. Similar to `presented_by`, the class must accept the resource collection as the only argument at initialization, and respond to `as_json` for output when used with the `Rapido::ApiController`. The `collection_presented_by` can also accept a list of arguments, as symbols, that should be pulled from the `params` hash and passed to presenter class at initialization as optional argments.
|
57
|
+
For example, if `params` contained a `:filter` parameter which should be used by the presenter , then the following would work:
|
60
58
|
|
61
|
-
|
62
|
-
|
63
|
-
`collection_presented_by WidgetsCollectionPresenter, :filter`
|
59
|
+
`presented_by WidgetsPresenter, :filter`
|
64
60
|
|
65
61
|
The `initialize` method of the presenter should be structured as such:
|
66
62
|
|
67
63
|
`def initialize(widgets, filter = nil)`
|
68
64
|
|
65
|
+
#### `collection_presented_by`
|
66
|
+
|
67
|
+
Specifies the class that will present a collection of resources, as in the index method. Similar to `presented_by`, the class must accept the resource collection as the only argument at initialization, and respond to `as_json` for output when used with the `Rapido::ApiController`. The `collection_presented_by` can also accept a list of arguments, as symbols, that should be pulled from the `params` hash and passed to presenter class at initialization as optional argments.
|
68
|
+
|
69
|
+
Collection presenters can also be provided args, similar to `presented_by`
|
70
|
+
|
69
71
|
#### `attr_permitted`
|
70
72
|
|
71
73
|
Accepts a list of symbols. These symbols specify the attributes that are supplied to StrongParameters as permitted parameters in `create` and `update` actions.
|
@@ -50,7 +50,8 @@ module Rapido
|
|
50
50
|
private
|
51
51
|
|
52
52
|
def present_resource(resource)
|
53
|
-
|
53
|
+
args = presenter_args.nil? ? nil : presenter_args.map { |arg| params[arg] }
|
54
|
+
return presenter.new(*[resource, *args]).as_json if presenter
|
54
55
|
resource.to_h
|
55
56
|
end
|
56
57
|
|
data/lib/rapido/controller.rb
CHANGED
@@ -87,8 +87,9 @@ module Rapido
|
|
87
87
|
resource_class_from_controller
|
88
88
|
end
|
89
89
|
|
90
|
-
def presented_by(presenter_class)
|
90
|
+
def presented_by(presenter_class, *args)
|
91
91
|
@presenter ||= presenter_class
|
92
|
+
@presenter_args = args if args.count > 0
|
92
93
|
end
|
93
94
|
end
|
94
95
|
|
@@ -159,6 +160,10 @@ module Rapido
|
|
159
160
|
setting(:presenter)
|
160
161
|
end
|
161
162
|
|
163
|
+
def presenter_args
|
164
|
+
setting(:presenter_args)
|
165
|
+
end
|
166
|
+
|
162
167
|
def resource
|
163
168
|
@resource ||= begin
|
164
169
|
if setting(:has_one)
|
data/lib/rapido/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-rapido
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Kirst
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|