Class: Charming::Response
- Inherits:
-
Data
- Object
- Data
- Charming::Response
- Defined in:
- lib/charming/response.rb
Overview
Response encapsulates a controller’s dispatch outcome — one of render text, navigate to another route, or quit. Rails-style factories (‘render`, `navigate`, `quit`) serve as the public API and map to :kind values that the Runtime interprets at the end of each event loop iteration.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.navigate(path) ⇒ Object
Factory constructing a NavigateResponse routing to the named path (string).
-
.quit ⇒ Object
Factory constructing a QuitResponse signalling termination of the top-level event loop.
-
.render(body) ⇒ Object
Factory constructing a Render response for displaying body text on the current screen.
Instance Method Summary collapse
-
#navigate? ⇒ Boolean
Returns ‘true` when this response is navigating to another screen or route.
-
#quit? ⇒ Boolean
Returns ‘true` when this response requests quitting the application.
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body
7 8 9 |
# File 'lib/charming/response.rb', line 7 def body @body end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind
7 8 9 |
# File 'lib/charming/response.rb', line 7 def kind @kind end |
#path ⇒ Object (readonly)
Returns the value of attribute path
7 8 9 |
# File 'lib/charming/response.rb', line 7 def path @path end |
Class Method Details
.navigate(path) ⇒ Object
Factory constructing a NavigateResponse routing to the named path (string).
14 15 16 |
# File 'lib/charming/response.rb', line 14 def self.navigate(path) new(kind: :navigate, body: "", path: path) end |
.quit ⇒ Object
Factory constructing a QuitResponse signalling termination of the top-level event loop.
19 20 21 |
# File 'lib/charming/response.rb', line 19 def self.quit new(kind: :quit, body: "", path: nil) end |
.render(body) ⇒ Object
Factory constructing a Render response for displaying body text on the current screen.
9 10 11 |
# File 'lib/charming/response.rb', line 9 def self.render(body) new(kind: :render, body: body, path: nil) end |
Instance Method Details
#navigate? ⇒ Boolean
Returns ‘true` when this response is navigating to another screen or route.
24 25 26 |
# File 'lib/charming/response.rb', line 24 def navigate? kind == :navigate end |
#quit? ⇒ Boolean
Returns ‘true` when this response requests quitting the application.
29 30 31 |
# File 'lib/charming/response.rb', line 29 def quit? kind == :quit end |