/usr/lib/ruby/vendor_ruby/innate/session/flash.rb is in ruby-innate 2013.02.21-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | module Innate
class Session
# The purpose of this class is to act as a unifier of the previous
# and current flash.
#
# Flash means pairs of keys and values that are held only over one
# request/response cycle. So you can assign a key/value in the current
# session and retrieve it in the current and following request.
#
# Please see the Innate::Helper::Flash for details on the usage in your
# application.
class Flash
include Enumerable
def initialize(session)
@session = session
end
# iterate over the combined session
def each(&block)
combined.each(&block)
end
# the current session[:FLASH_PREVIOUS]
def previous
session[:FLASH_PREVIOUS] || {}
end
# the current session[:FLASH]
def current
session[:FLASH] ||= {}
end
# combined key/value pairs of previous and current
# current keys overshadow the old ones.
def combined
previous.merge(current)
end
# flash[key] in your Controller
def [](key)
combined[key]
end
# flash[key] = value in your Controller
def []=(key, value)
prev = session[:FLASH] || {}
prev[key] = value
session[:FLASH] = prev
end
# Inspects combined
def inspect
combined.inspect
end
# Delete a key
def delete(key)
previous.delete(key)
current.delete(key)
end
# check if combined is empty
def empty?
combined.empty?
end
# merge into current
def merge!(hash)
current.merge!(hash)
end
# merge on current
def merge(hash)
current.merge(hash)
end
# Rotation means current values are assigned as old values for the next
# request.
def rotate!
old = session.delete(:FLASH)
session[:FLASH_PREVIOUS] = old if old
end
private
# Associated session object
def session
@session
end
end
end
end
|