Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Refactor using @cover suggestion
  • Loading branch information
kevintraver committed Aug 9, 2015
commit 2e08148e2bbe953fab5747df729303d597d76e97
25 changes: 14 additions & 11 deletions lib/rspec_api_documentation/dsl/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,23 @@ def delete_extra_param(key)

def set_param(hash, param)
key = param[:name]
return hash if !respond_to?(key) || in_path?(key)
return hash if in_path?(key)

if scope = param[:scope]
if scope.is_a?(Array)
hash.merge!(scope.reverse.inject({key => send(key)}) { |a,n| { n.to_s => a }})
else
hash[scope.to_s] ||= {}
hash[scope.to_s][key] = send(key)
end
else
hash[key] = send(key)
keys = [param[:scope], key].flatten.compact
method_name = keys.join('_')

unless respond_to?(method_name)
method_name = key
return hash unless respond_to?(method_name)
end

hash
hash.deep_merge(build_param_hash(keys, method_name))
end

def build_param_hash(keys, method_name)
value = keys[1] ? build_param_hash(keys[1..-1], method_name) : send(method_name)
{ keys[0].to_s => value }
end

end
end