Module: Katello::Api::V2::Rendering

Included in:
ApiController, OrganizationsController
Defined in:
app/lib/katello/api/v2/rendering.rb

Instance Method Summary collapse

Instance Method Details

#respond_for_async(options = {}) ⇒ Object



30
31
32
33
# File 'app/lib/katello/api/v2/rendering.rb', line 30

def respond_for_async(options = {})
  options[:status] ||= 202
  try_specific_resource_template(options[:template] || params[:action], "async", options)
end

#respond_for_bulk_async(options = {}) ⇒ Object



35
36
37
38
# File 'app/lib/katello/api/v2/rendering.rb', line 35

def respond_for_bulk_async(options = {})
  options[:status] ||= 202
  try_specific_resource_template(options[:template] || params[:action], "bulk_async", options)
end

#respond_for_create(options = {}) ⇒ Object



14
15
16
# File 'app/lib/katello/api/v2/rendering.rb', line 14

def respond_for_create(options = {})
  try_specific_resource_template(options[:template] || params[:action], params[:action], options)
end

#respond_for_destroy(options = {}) ⇒ Object



22
23
24
# File 'app/lib/katello/api/v2/rendering.rb', line 22

def respond_for_destroy(options = {})
  try_specific_resource_template(options[:template] || params[:action], params[:action], options)
end

#respond_for_index(options = {}) ⇒ Object



10
11
12
# File 'app/lib/katello/api/v2/rendering.rb', line 10

def respond_for_index(options = {})
  try_specific_collection_template(options[:template] || params[:action], params[:action], options)
end

#respond_for_show(options = {}) ⇒ Object



5
6
7
8
# File 'app/lib/katello/api/v2/rendering.rb', line 5

def respond_for_show(options = {})
  respond_with_template_resource(options[:template] || 'show', options[:resource_name] || controller_name,
                                 options)
end

#respond_for_status(options = {}) ⇒ Object



26
27
28
# File 'app/lib/katello/api/v2/rendering.rb', line 26

def respond_for_status(options = {})
  try_specific_resource_template(options[:template] || params[:action], "status", options)
end

#respond_for_update(options = {}) ⇒ Object



18
19
20
# File 'app/lib/katello/api/v2/rendering.rb', line 18

def respond_for_update(options = {})
  try_specific_resource_template(options[:template] || params[:action], params[:action], options)
end

#respond_with_template(action, resource_name, options = {}, &_block) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'app/lib/katello/api/v2/rendering.rb', line 40

def respond_with_template(action, resource_name, options = {}, &_block)
  yield if block_given?
  status = options[:status] || 200

  render :template => "katello/api/v2/#{resource_name}/#{action}",
         :status => status,
         :locals => { :object_name => options[:object_name],
                      :root_name => options[:root_name] },
         :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, options = {})
  options[:layout] ||= "collection"
  options[:root_name] = params[:root_name] || "results"
  respond_with_template(action, resource_name, options) do
    @collection = options[:collection] unless options[: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, options = {})
  options[:layout] ||= "resource"
  options[:object_name] = params[:object_name]
  respond_with_template(action, resource_name, options) do
    @resource = options[:resource] unless options[: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, options = {})
  respond_with_template_collection(action, controller_name, options)
rescue ActionView::MissingTemplate
  respond_with_template_collection(common_action, "common", options)
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, options = {})
  respond_with_template_resource(action, controller_name, options)
rescue ActionView::MissingTemplate
  respond_with_template_resource(common_action, "common", options)
end