Module: UnitController::CaptureRender

Defined in:
lib/unit_controller/capture_render.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#renderedObject (readonly)

Returns the value of attribute rendered.



3
4
5
# File 'lib/unit_controller/capture_render.rb', line 3

def rendered
  @rendered
end

Class Method Details

.included(klass) ⇒ Object



36
37
38
39
40
# File 'lib/unit_controller/capture_render.rb', line 36

def self.included(klass)
  klass.class_eval do
    alias_method_chain :render, :unit_controller
  end
end

Instance Method Details

#do_not_render_viewObject



5
6
7
# File 'lib/unit_controller/capture_render.rb', line 5

def do_not_render_view
  @render_view = false
end

#render_view?Boolean

Returns:



9
10
11
# File 'lib/unit_controller/capture_render.rb', line 9

def render_view?
  instance_variables.include?("@render_view") ? @render_view : true
end

#render_with_unit_controller(*args, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/unit_controller/capture_render.rb', line 13

def render_with_unit_controller(*args, &block)
  @rendered = args.first
  if render_view?
    render_without_unit_controller *args, &block
  else
    raise ActionController::DoubleRenderError, "Can only render or redirect once per action" if performed?
    @performed_render = true
    if args.first.is_a?(Hash)
      status = args.first[:status]
    elsif args.last.is_a?(Hash)
      status = args.last[:status]
    end
    if status
      status = ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[status] if status.is_a?(Symbol)
      #response.headers["Status"] = status.to_s
      response.status = status
    else
      #response.headers["Status"] = ActionController::Base::DEFAULT_RENDER_STATUS_CODE
      response.status = ActionController::Base::DEFAULT_RENDER_STATUS_CODE
    end
  end
end