rails-rapido 0.6.0 → 0.6.1

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
  SHA256:
3
- metadata.gz: 3f3dd10cd161414576384c3421ae4ea86a146794d71eadb7073c29ae1428bfdb
4
- data.tar.gz: 97433e93ac49b4f221c38fe396d273d312a5953e1ec1878b98c7b618052020cc
3
+ metadata.gz: 4c7123a3a6f6a4c588644079e1aa18d1f2f43f65fba2a073bdf65ad5d969f84f
4
+ data.tar.gz: 06b29712f5d93a0121b71a6f5af810cdbf9c3869049a202a2f5923f8333743f8
5
5
  SHA512:
6
- metadata.gz: 547d9b3d33283f4f6c5ca1c05cf16306478a7c919728006f47087c38fd515007440d7093165868e7feb85c9a3e8755dccb3a736f12d0944ec29e3d2b10c85f9d
7
- data.tar.gz: d1d5653905181c2833d7b75fecb1fd3b6877c20c5149a282aca7f1c6a040fe1800a951b469784cd9f2554cf985dea52c671fd828e0b91da8105913c83f5ab6ae
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
- #### `collection_presented_by`
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
- For example, if `params` contained a `:filter` parameter which should be used by the presenter to filter the collection, then the following would work:
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
- return presenter.new(resource).as_json if presenter
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
 
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Rapido
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.1'
3
3
  end
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.0
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-09-28 00:00:00.000000000 Z
11
+ date: 2018-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler