13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/grape/nested_resources.rb', line 13
def nested_resource(**kwargs)
kwargs.each do |key, value|
root = key.to_s.pluralize
paths = []
prepared_value = Array(value).flatten.map { |a| a.to_s.pluralize }
paths << _build_rest_uri(root, *prepared_value)
paths << prepared_value.pop
Grape::Validations::ParamsScope.new(api: self, type: Hash) do
[root, *[prepared_value]].flatten.each do |param|
attr = param.singularize.foreign_key
requires attr.to_sym, type: Integer, desc: attr.titleize
end
end
paths.each { |path| yield path }
end
end
|