Module: Katello::Routing::MapperExtensions

Defined in:
app/lib/katello/api/mapper_extensions.rb

Instance Method Summary collapse

Instance Method Details

#api_attachable_resources(resource_plural_name, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/lib/katello/api/mapper_extensions.rb', line 13

def api_attachable_resources(resource_plural_name, options = {})
  resource_singular_name = options.try(:delete, :resource_name)
  resource_singular_name ||= resource_plural_name.to_s.singularize

  controller = options.delete(:controller)

  api_resources resource_plural_name, :controller => controller, :only => [] do
    params = { :on => :collection, :action => "add_" + resource_singular_name.to_s }
    post :index, params.merge(options)

    params = { :on => :member, :action => "remove_" + resource_singular_name.to_s }
    delete :destroy, params.merge(options)
  end
end

#api_resources(*args, &block) ⇒ Object



4
5
6
7
8
9
10
11
# File 'app/lib/katello/api/mapper_extensions.rb', line 4

def api_resources(*args, &block)
  options          = args.extract_options!
  options[:except] = Array(options[:except])
  options[:except].push(:new, :edit)

  args << options
  resources(*args, &block)
end