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.

escapes carries any out-of-band terminal sequences (image transmissions, clipboard writes, notifications, window-title changes) gathered during the dispatch. The Runtime flushes them straight to the backend, bypassing the line-based frame pipeline. It is empty for ordinary responses.

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



11
12
13
# File 'lib/charming/response.rb', line 11

def body
  @body
end

#escapesObject (readonly)

Returns the value of attribute escapes

Returns:

  • (Object)

    the current value of escapes



11
12
13
# File 'lib/charming/response.rb', line 11

def escapes
  @escapes
end

#kindObject (readonly)

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



11
12
13
# File 'lib/charming/response.rb', line 11

def kind
  @kind
end

#pathObject (readonly)

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



11
12
13
# File 'lib/charming/response.rb', line 11

def path
  @path
end

Class Method Details

Factory constructing a NavigateResponse routing to the named path (string).



19
20
21
# File 'lib/charming/response.rb', line 19

def self.navigate(path)
  new(kind: :navigate, body: "", path: path, escapes: [])
end

.quitObject

Factory constructing a QuitResponse signalling termination of the top-level event loop.



24
25
26
# File 'lib/charming/response.rb', line 24

def self.quit
  new(kind: :quit, body: "", path: nil, escapes: [])
end

.render(body, escapes: []) ⇒ Object

Factory constructing a Render response for displaying body text on the current screen. escapes is the list of out-of-band sequences gathered during the dispatch (defaults to none).



14
15
16
# File 'lib/charming/response.rb', line 14

def self.render(body, escapes: [])
  new(kind: :render, body: body, path: nil, escapes: escapes)
end

Instance Method Details

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

Returns:

  • (Boolean)


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

def navigate?
  kind == :navigate
end

#quit?Boolean

Returns true when this response requests quitting the application.

Returns:

  • (Boolean)


34
35
36
# File 'lib/charming/response.rb', line 34

def quit?
  kind == :quit
end