Project

General

Profile

« Previous | Next » 

Revision c1a23d77

Added by Joseph Magen almost 11 years ago

fixes #2869 - refactor method find_nested_obj into API::BaseController

View differences:

app/controllers/api/v2/puppetclasses_controller.rb
include Api::Version2
include Api::TaxonomyScope
before_filter :find_nested_object, :only => [:index, :show]
before_filter :find_optional_nested_object, :only => [:index, :show]
api :GET, "/puppetclasses/", "List all puppetclasses."
api :GET, "/hosts/:host_id/puppetclasses", "List all puppetclasses for host"
......
param :id, String, :required => true, :desc => "id of puppetclass"
def show
if @nested_obj
@puppetclass = @nested_obj.puppetclasses.find(params[:id])
if nested_obj
@puppetclass = nested_obj.puppetclasses.find(params[:id])
end
end
private
attr_reader :nested_obj
def find_nested_object
params.keys.each do |param|
if param =~ /(\w+)_id$/
resource_identifying_attributes.each do |key|
find_method = "find_by_#{key}"
@nested_obj ||= $1.classify.constantize.send(find_method, params[param])
end
end
end
return @nested_obj
def allowed_nested_id
%w(environment_id host_id hostgroup_id)
end
end

Also available in: Unified diff