grape-nested_resources 0.2.1 → 0.3.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: 9bf936577df2ce4cfe0f064e786f02be655bd69d
4
- data.tar.gz: f31f59cead70541496e043c37eb5b024ee944655
3
+ metadata.gz: b542e342e88b34733252e8bef4120a5388934901
4
+ data.tar.gz: f9e4397b25734f8631dcff310439a29cc9a82b6a
5
5
  SHA512:
6
- metadata.gz: 2e7b96e7baabb7e64726dab338f5ebd79a453c90f631a13843fe672bd00d6dd3c0447fa4fdd62ed5e0981b5de3994019b894017eb1c87c8f37a1622be6cc36ca
7
- data.tar.gz: babcbc4292e009911137ae64f31f2cf2509689188014a03fa66c0699f155a618a69e8f43642d9853c414411a457fa6b400202908c0ee8e26b750732730c854cf
6
+ metadata.gz: 52d21bb61a1e499594d828839b03d753fd17c147c01246da3b29c6d407b190f6319e6c8e2716e2084b2b7d1b79a2cd0d5c27d51e70359d634810b014171fb029
7
+ data.tar.gz: 5452929fc853772848342b724def4f5d4021e91c4a8f3ed1708730f2cedae47b2c1106c13c79a1a4e55000d539b7d2feaf4d0895f875ce1c433897c998a08d82
@@ -17,17 +17,22 @@ module Grape
17
17
  paths << _build_rest_uri(root, *prepared_value)
18
18
  paths << prepared_value.pop
19
19
 
20
- Grape::Validations::ParamsScope.new(api: self, type: Hash) do
21
- [root, *[prepared_value]].flatten.each do |param|
22
- attr = param.singularize.foreign_key
23
- requires attr.to_sym, type: Integer, desc: attr.titleize
24
- end
20
+ nested_params = [root, *[prepared_value]].flatten.map do |param|
21
+ param.singularize.foreign_key
25
22
  end
26
23
 
27
- paths.each { |path| yield path }
24
+ paths.each do |path|
25
+ resource path do
26
+ yield nested_params
27
+ end
28
+ end
28
29
  end
29
30
  end
30
31
 
32
+ def add_required_params(params)
33
+ Grape::Validations::ParamsScope.new(api: self, type: Hash).add_required_params(params)
34
+ end
35
+
31
36
  private
32
37
 
33
38
  def _build_rest_uri(*elements)
@@ -6,6 +6,12 @@ module Grape
6
6
  optional(*attrs, &block)
7
7
  end
8
8
 
9
+ def add_required_params(params)
10
+ params.flatten.map do |param|
11
+ requires param.to_sym, type: Integer, desc: param.titleize
12
+ end
13
+ end
14
+
9
15
  end
10
16
  end
11
17
  end
@@ -1,5 +1,5 @@
1
1
  module Grape
2
2
  module NestedResources
3
- VERSION = '0.2.1'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-nested_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikhail Grachev