Module: Katello::Api::V2::Rendering
- Included in:
- ApiController, OrganizationsController
- Defined in:
- app/lib/katello/api/v2/rendering.rb
Instance Method Summary collapse
- #respond_for_async(options = {}) ⇒ Object
- #respond_for_bulk_async(options = {}) ⇒ Object
- #respond_for_create(options = {}) ⇒ Object
- #respond_for_destroy(options = {}) ⇒ Object
- #respond_for_index(options = {}) ⇒ Object
- #respond_for_show(options = {}) ⇒ Object
- #respond_for_status(options = {}) ⇒ Object
- #respond_for_update(options = {}) ⇒ Object
- #respond_with_template(action, resource_name, options = {}, &_block) ⇒ Object
- #respond_with_template_collection(action, resource_name, options = {}) ⇒ Object
- #respond_with_template_resource(action, resource_name, options = {}) ⇒ Object
- #try_specific_collection_template(action, common_action, options = {}) ⇒ Object
- #try_specific_resource_template(action, common_action, options = {}) ⇒ Object
Instance Method Details
#respond_for_async(options = {}) ⇒ Object
31 32 33 34 |
# File 'app/lib/katello/api/v2/rendering.rb', line 31 def respond_for_async( = {}) [:status] ||= 202 try_specific_resource_template([:template] || params[:action], "async", ) end |
#respond_for_bulk_async(options = {}) ⇒ Object
36 37 38 39 |
# File 'app/lib/katello/api/v2/rendering.rb', line 36 def respond_for_bulk_async( = {}) [:status] ||= 202 try_specific_resource_template([:template] || params[:action], "bulk_async", ) end |
#respond_for_create(options = {}) ⇒ Object
14 15 16 17 |
# File 'app/lib/katello/api/v2/rendering.rb', line 14 def respond_for_create( = {}) [:status] ||= 201 try_specific_resource_template([:template] || params[:action], params[:action], ) end |
#respond_for_destroy(options = {}) ⇒ Object
23 24 25 |
# File 'app/lib/katello/api/v2/rendering.rb', line 23 def respond_for_destroy( = {}) try_specific_resource_template([:template] || params[:action], params[:action], ) end |
#respond_for_index(options = {}) ⇒ Object
10 11 12 |
# File 'app/lib/katello/api/v2/rendering.rb', line 10 def respond_for_index( = {}) try_specific_collection_template([:template] || params[:action], params[:action], ) end |
#respond_for_show(options = {}) ⇒ Object
5 6 7 8 |
# File 'app/lib/katello/api/v2/rendering.rb', line 5 def respond_for_show( = {}) respond_with_template_resource([:template] || 'show', [:resource_name] || controller_name, ) end |
#respond_for_status(options = {}) ⇒ Object
27 28 29 |
# File 'app/lib/katello/api/v2/rendering.rb', line 27 def respond_for_status( = {}) try_specific_resource_template([:template] || params[:action], "status", ) end |
#respond_for_update(options = {}) ⇒ Object
19 20 21 |
# File 'app/lib/katello/api/v2/rendering.rb', line 19 def respond_for_update( = {}) try_specific_resource_template([:template] || params[:action], params[:action], ) end |
#respond_with_template(action, resource_name, options = {}, &_block) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'app/lib/katello/api/v2/rendering.rb', line 41 def respond_with_template(action, resource_name, = {}, &_block) yield if block_given? status = [:status] || 200 render :template => "katello/api/v2/#{resource_name}/#{action}", :status => status, :locals => .slice(:object_name, :root_name, :locals), :layout => "katello/api/v2/layouts/#{options[:layout]}" end |
#respond_with_template_collection(action, resource_name, options = {}) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'app/lib/katello/api/v2/rendering.rb', line 60 def respond_with_template_collection(action, resource_name, = {}) [:layout] ||= "collection" [:root_name] = params[:root_name] || "results" respond_with_template(action, resource_name, ) do @collection = [:collection] unless [:collection].nil? @collection = resource_collection if @collection.nil? end end |
#respond_with_template_resource(action, resource_name, options = {}) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'app/lib/katello/api/v2/rendering.rb', line 51 def respond_with_template_resource(action, resource_name, = {}) [:layout] ||= "resource" [:object_name] = params[:object_name] respond_with_template(action, resource_name, ) do @resource = [:resource] unless [:resource].nil? @resource = resource if @resource.nil? end end |
#try_specific_collection_template(action, common_action, options = {}) ⇒ Object
75 76 77 78 79 |
# File 'app/lib/katello/api/v2/rendering.rb', line 75 def try_specific_collection_template(action, common_action, = {}) respond_with_template_collection(action, controller_name, ) rescue ActionView::MissingTemplate respond_with_template_collection(common_action, "common", ) end |
#try_specific_resource_template(action, common_action, options = {}) ⇒ Object
69 70 71 72 73 |
# File 'app/lib/katello/api/v2/rendering.rb', line 69 def try_specific_resource_template(action, common_action, = {}) respond_with_template_resource(action, controller_name, ) rescue ActionView::MissingTemplate respond_with_template_resource(common_action, "common", ) end |