Class: Flash

Inherits:
Object
  • Object
show all
Defined in:
lib/fresco/runtime/runtime.rb

Overview

One-shot key/value bag that survives exactly one request bounce. Read side (‘read_data`) carries messages set on the previous request; write side (`write_data`) collects messages that should survive into the next one. Backed by the signed session cookie —flash is a thin wrapper on top of Session, not its own cookie.

Lifecycle (per request):

1. maybe_load_session! pulls `_flash.<key>` entries out of the
   newly-loaded session into req.flash.read_data, removes them
   from the session, and marks the session dirty (so the cleared
   state ships back).
2. Handler reads via req.flash.get(k); writes via req.flash.set(k, v).
3. attach_session_cookie! bakes write_data back into the session
   as `_flash.<key>` entries, then session signing proceeds as
   usual.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFlash

Returns a new instance of Flash.



332
333
334
335
336
337
# File 'lib/fresco/runtime/runtime.rb', line 332

def initialize
  @read_data = { "__t" => "" }
  @read_data.delete("__t")
  @write_data = { "__t" => "" }
  @write_data.delete("__t")
end

Instance Attribute Details

#read_dataObject (readonly)

Returns the value of attribute read_data.



330
331
332
# File 'lib/fresco/runtime/runtime.rb', line 330

def read_data
  @read_data
end

#write_dataObject (readonly)

Returns the value of attribute write_data.



330
331
332
# File 'lib/fresco/runtime/runtime.rb', line 330

def write_data
  @write_data
end

Instance Method Details

#get(k = "") ⇒ Object

see Session#get re ‘|| “”`



339
# File 'lib/fresco/runtime/runtime.rb', line 339

def get(k = "");    @read_data[k] || ""; end

#has?(k = "") ⇒ Boolean

Returns:

  • (Boolean)


340
# File 'lib/fresco/runtime/runtime.rb', line 340

def has?(k = "");   @read_data.key?(k);   end

#lengthObject



342
# File 'lib/fresco/runtime/runtime.rb', line 342

def length; @read_data.length; end

#set(k = "", v = "") ⇒ Object



341
# File 'lib/fresco/runtime/runtime.rb', line 341

def set(k = "", v = ""); @write_data[k] = v; end