Class: Plutonium::Interaction::Response::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/plutonium/interaction/response/base.rb

Overview

This class is abstract.

Subclass and override #execute to implement specific response behavior.

Base class for interaction responses.

This class provides common functionality for handling flash messages and processing responses in controllers.

Direct Known Subclasses

Failure, File, Null, Redirect, Render

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, **options) ⇒ Base

Initializes a new Response::Base instance.



16
17
18
19
20
# File 'lib/plutonium/interaction/response/base.rb', line 16

def initialize(*args, **options)
  @args = args
  @options = options
  @flash = []
end

Instance Attribute Details

#flashArray<Array(String, Symbol)> (readonly)

Returns Flash messages associated with the response.

Returns:

  • (Array<Array(String, Symbol)>)

    Flash messages associated with the response.



13
14
15
# File 'lib/plutonium/interaction/response/base.rb', line 13

def flash
  @flash
end

Instance Method Details

#process(controller) {|Object| ... } ⇒ void

This method returns an undefined value.

Processes the response in the context of a controller.

Parameters:

  • controller (ActionController::Base)

    The controller instance.

Yields:

  • (Object)

    Executed if the response doesn’t handle its own rendering.



27
28
29
30
# File 'lib/plutonium/interaction/response/base.rb', line 27

def process(controller, &)
  set_flash(controller)
  execute(controller, &)
end

#with_flash(messages) ⇒ self

Adds flash messages to the response.

Parameters:

  • messages (Array<Array(String, Symbol)>)

    The messages to add.

Returns:

  • (self)


36
37
38
39
# File 'lib/plutonium/interaction/response/base.rb', line 36

def with_flash(messages)
  @flash.concat(messages) unless messages.blank?
  self
end