File: flash.rb

package info (click to toggle)
libinnate-ruby 2010.07-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 812 kB
  • ctags: 621
  • sloc: ruby: 4,242; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 1,013 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module Innate
  module Helper
    # Simple access to session.flash.
    #
    # Flash is a mechanism using sessions to provide a rotating holder of
    # key/value pairs.
    #
    # Every request that is made will rotate one step, dropping contents stored
    # two requests ago.
    #
    # The purpose of this class is to provide an easy way of setting/retrieving
    # from the current flash.
    #
    # Flash is a way to keep a temporary pairs of keys and values for the duration
    # of two requests, the current and following.
    #
    # Very vague Example:
    #
    # On the first request, for example on registering:
    #
    #   flash[:error] = "You should reconsider your username, it's taken already"
    #   redirect r(:register)
    #
    # This is the request from the redirect:
    #
    #   do_stuff if flash[:error]
    #
    # On the request after this, flash[:error] is gone.
    module Flash
      # Just for convenience
      def flash
        session.flash
      end
    end
  end
end