6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/ruby-swagger/grape/grape_presenter.rb', line 6
def api_present(*args)
args_list = args || []
options = {}
if args_list.count == 2
if args_list.last.is_a?(Hash)
options = args_list.last
else
raise ArgumentError.new "The expected second argument for api_present is a Hash, but I got a #{args_list.last.class}"
end
elsif args_list.count == 1
args_list << options
elsif args_list.count > 2 || args_list.count == 0
raise ArgumentError.new "Invalid number of arguments - got #{args_list.count}. expected 1 or 2 parameters"
end
if route.route_response.present? && route.route_response[:entity].present? && !options[:with].present? && route.route_response[:entity].is_a?(Class)
options[:with] = route.route_response[:entity]
end
if route.route_response.present? && route.route_response[:root].present? && !options[:root].present? && route.route_response[:root].is_a?(String)
options[:root] = route.route_response[:root]
end
options[:current_user] = current_user if defined?(current_user)
present(*args_list)
end
|