Skip to content

Commit 2e08148

Browse files
committed
Refactor using @cover suggestion
1 parent 090c13a commit 2e08148

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/rspec_api_documentation/dsl/endpoint.rb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,23 @@ def delete_extra_param(key)
148148

149149
def set_param(hash, param)
150150
key = param[:name]
151-
return hash if !respond_to?(key) || in_path?(key)
151+
return hash if in_path?(key)
152152

153-
if scope = param[:scope]
154-
if scope.is_a?(Array)
155-
hash.merge!(scope.reverse.inject({key => send(key)}) { |a,n| { n.to_s => a }})
156-
else
157-
hash[scope.to_s] ||= {}
158-
hash[scope.to_s][key] = send(key)
159-
end
160-
else
161-
hash[key] = send(key)
153+
keys = [param[:scope], key].flatten.compact
154+
method_name = keys.join('_')
155+
156+
unless respond_to?(method_name)
157+
method_name = key
158+
return hash unless respond_to?(method_name)
162159
end
163160

164-
hash
161+
hash.deep_merge(build_param_hash(keys, method_name))
165162
end
163+
164+
def build_param_hash(keys, method_name)
165+
value = keys[1] ? build_param_hash(keys[1..-1], method_name) : send(method_name)
166+
{ keys[0].to_s => value }
167+
end
168+
166169
end
167170
end

0 commit comments

Comments
 (0)