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
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/rails/surrender/controller_additions.rb', line 17
def surrender(resource, status: 200, reload: true, include: [], exclude: [])
resource = filter resource if parsed_query_params.filter?
if parsed_query_params.sort?
resource = sort resource
response.['X-Sort'] = parsed_query_params.sort.request
end
if paginate?(resource)
resource = paginate resource
response.['X-Pagination'] = (resource)
end
surrender_response = if parsed_query_params.count?
Render::Count.new(resource).parse
elsif parsed_query_params.ids?
Render::Ids.new(resource).parse
else
config = Render::Configuration.new(
resource_class: resource_class(resource),
reload_resource: reload,
user_exclude: parsed_query_params.exclude,
user_include: parsed_query_params.include,
ctrl_exclude: exclude,
ctrl_include: include
)
Render::Resource.new(resource: resource,
ability: ability,
config: config).parse
end
surrender_response.data = yield surrender_response.data if block_given?
render(json: surrender_response.json_data, status: status)
end
|