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
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/lanes/api/routing.rb', line 24
def resources(model, options = {})
path = options[:path] || model.api_path
controller = options[:controller] || Lanes::API::Controller
parent_attribute = false
if options[:under]
parent_attribute = options[:parent_attribute] || options[:under].underscore.singularize+'_id'
end
prefix = parent_attribute ? parent_attribute + '/' : ''
if controller.method_defined?(:perform_retrieval)
get "#{prefix}#{path}/?:id?.json",
&RequestWrapper.get(model, controller, parent_attribute)
end
if controller.method_defined?(:perform_creation)
post "#{prefix}#{path}.json",
&RequestWrapper.post(model, controller, parent_attribute)
end
unless options[:immutable]
if controller.method_defined?(:perform_update)
patch "#{prefix}#{path}/?:id?.json",
&RequestWrapper.update(model, controller, parent_attribute)
put "#{prefix}#{path}/?:id?.json",
&RequestWrapper.update(model, controller, parent_attribute)
end
if controller.method_defined?(:perform_destroy) and not options[:indestructible]
delete "#{prefix}#{path}/?:id?.json",
&RequestWrapper.delete(model, controller, parent_attribute)
end
end
end
|