Class: Charming::Response

Inherits:
Data
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



7
8
9
# File 'lib/charming/response.rb', line 7

def body
  @body
end

#kindObject (readonly)

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



7
8
9
# File 'lib/charming/response.rb', line 7

def kind
  @kind
end

#pathObject (readonly)

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



7
8
9
# File 'lib/charming/response.rb', line 7

def path
  @path
end

Class Method Details

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

.quitObject

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

Returns ‘true` when this response is navigating to another screen or route.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


29
30
31
# File 'lib/charming/response.rb', line 29

def quit?
  kind == :quit
end