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



24
25
26
27
28
# File 'lib/unit_controller/capture_render.rb', line 24

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:

  • (Boolean)


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
# 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
    response.headers["Status"] = ActionController::Base::DEFAULT_RENDER_STATUS_CODE
  end
end