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
|
# File 'lib/sweet_actions/routes_helpers.rb', line 10
def create_sweet_actions(resource, options = {})
path = options.fetch(:path, '/')
namespace = options.fetch(:namespace, nil)
singular = resource.to_s.singularize
resource_class = singular.classify
actions = %i[collect show create update destroy]
only = options.fetch(:only, actions)
base_path = "#{path}#{resource}"
options = options.merge(resource_name: resource_class, namespace: namespace)
if only.include?(:collect) || only.include?(:index)
create_sweet_action(:get, base_path, :collect, options)
end
if only.include?(:show)
create_sweet_action(:get, "#{base_path}/:id", :show, options)
end
if only.include?(:create)
create_sweet_action(:post, base_path, :create, options)
end
if only.include?(:update)
create_sweet_action(:put, "#{base_path}/:id", :update, options)
end
if only.include?(:destroy)
create_sweet_action(:delete, "#{base_path}/:id", :destroy, options)
end
end
|