Class: Plutonium::Interaction::Outcome::Success

Inherits:
Plutonium::Interaction::Outcome show all
Defined in:
lib/plutonium/interaction/outcome.rb

Overview

Represents a successful outcome of an interaction.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Plutonium::Interaction::Outcome

#failure?, #messages, #success?, #with_message

Constructor Details

#initialize(value) ⇒ Success

Returns a new instance of Success.

Parameters:

  • value (Object)

    The value to be wrapped in this successful outcome.



69
70
71
# File 'lib/plutonium/interaction/outcome.rb', line 69

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns The value wrapped by this successful outcome.

Returns:

  • (Object)

    The value wrapped by this successful outcome.



66
67
68
# File 'lib/plutonium/interaction/outcome.rb', line 66

def value
  @value
end

Instance Method Details

#and_then {|Object| ... } ⇒ Outcome

Chains another operation to be executed with the value of this outcome.

Yields:

  • (Object)

    The value wrapped by this outcome.

Returns:

  • (Outcome)

    The result of the yielded block.



77
78
79
# File 'lib/plutonium/interaction/outcome.rb', line 77

def and_then
  yield value
end

#to_responsePlutonium::Interaction::Response::Base

Converts this successful outcome to a response object.

Returns:



106
107
108
109
110
111
# File 'lib/plutonium/interaction/outcome.rb', line 106

def to_response
  @to_response ||= begin
    @response ||= Response::Null.new(value)
    @response.with_flash(messages)
  end
end

#with_file_responseObject



99
100
101
# File 'lib/plutonium/interaction/outcome.rb', line 99

def with_file_response(*, **)
  with_response(Response::File.new(*, **))
end

#with_redirect_responseObject



91
92
93
# File 'lib/plutonium/interaction/outcome.rb', line 91

def with_redirect_response(*, **)
  with_response(Response::Redirect.new(*, **))
end

#with_render_responseObject



95
96
97
# File 'lib/plutonium/interaction/outcome.rb', line 95

def with_render_response(*, **)
  with_response(Response::Render.new(*, **))
end

#with_response(response) ⇒ self

Sets the response for this successful outcome.

Parameters:

Returns:

  • (self)


85
86
87
88
89
# File 'lib/plutonium/interaction/outcome.rb', line 85

def with_response(response)
  @to_response = nil
  @response = response
  self
end