nakajima-sinatra-flash 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sinatra-flash.rb +47 -0
- metadata +62 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
module Sinatra
|
2
|
+
module Flash
|
3
|
+
# Implements bracket accessors for storing and retrieving flash entries.
|
4
|
+
class FlashHash
|
5
|
+
def initialize(session)
|
6
|
+
@session = session
|
7
|
+
@session[:__FLASH__] ||= {}
|
8
|
+
end
|
9
|
+
|
10
|
+
# Remove an entry from the session and return its value. Cache result in
|
11
|
+
# the instance cache.
|
12
|
+
def [](key)
|
13
|
+
cache[key] ||= values.delete(key)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Store the entry in the session, updating the instance cache as well.
|
17
|
+
def []=(key,val)
|
18
|
+
cache[key] = values[key] = val
|
19
|
+
end
|
20
|
+
|
21
|
+
# Hide the underlying :__FLASH__ session key and only expose values stored
|
22
|
+
# in the flash.
|
23
|
+
def inspect
|
24
|
+
'#<FlashHash @values=%s>' % [values.inspect]
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# Maintain an instance-level cache of retrieved flash entries. These entries
|
30
|
+
# will have been removed from the session, but are still available through
|
31
|
+
# the cache.
|
32
|
+
def cache
|
33
|
+
@cache ||= {}
|
34
|
+
end
|
35
|
+
|
36
|
+
# Helper to access flash entries from :__FLASH__ session value. This key
|
37
|
+
# is used to prevent collisions with other user-defined session values.
|
38
|
+
def values
|
39
|
+
@session[:__FLASH__]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def flash
|
44
|
+
@flash ||= Sinatra::Flash::FlashHash.new(session)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nakajima-sinatra-flash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pat Nakajima
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-26 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sinatra
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: patnakajima@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- lib/sinatra-flash.rb
|
35
|
+
has_rdoc: false
|
36
|
+
homepage:
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.2.0
|
58
|
+
signing_key:
|
59
|
+
specification_version: 2
|
60
|
+
summary: Flash hash implementation for Sinatra
|
61
|
+
test_files: []
|
62
|
+
|