tiny-rack-flash 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/README.md +4 -2
- data/lib/tiny_rack_flash.rb +16 -20
- data/tests.rb +7 -2
- data/tiny-rack-flash.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
NDZkNzU5YzEwNmNiMDE3ZWE0MzEzMWJkYTBhNTEyM2NjOGYyOTk1MA==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
YTZlZjM1ZGZiYjg2YWYyZmNmOTM4OWNiNjdhNDI0YjYxYjdlZDYyMQ==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
NjhkOTY5MzI5NTk0MjNmZDcxYTYzMjFmN2E2MGFmNmIwYzU2NmIxMmE0ODdk
|
|
10
|
+
ZTliOGZjZjAxYzRjYjlmMzJjMDY4YTA5ZGFkZWVlM2RjNGJmMDVlZDdlODMx
|
|
11
|
+
ZjBiYTU5OGVjMGRiZGQ5NjVkZWVhZmRiYmY4ZGE2OWYwNjE5OTQ=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
ZGRlNjZkYzMxMGFjNzllZDVmZTk3ZGU4NmRmMzg5ZjI4YTJlYTMyMDE2ZmY1
|
|
14
|
+
NTZkNGU0NDViNjc1MWFmMWY1YTNiODc0YWFkNzdjM2ViZTYyMzliNDE3ODk4
|
|
15
|
+
N2UwMTIxOWU5ZTUwYWE1NzJhMGM0OWU2YTBiZGUxMTU3ODk4Mzg=
|
data/README.md
CHANGED
|
@@ -23,9 +23,11 @@ Or install it yourself as:
|
|
|
23
23
|
Inside your main Rack class (e.g., `Sinatra::Base` or `Cuba`), simply add a
|
|
24
24
|
|
|
25
25
|
require 'tiny_rack_flash'
|
|
26
|
-
|
|
26
|
+
use TinyRackFlash do |helpers|
|
|
27
|
+
include helpers # adds `flash` method to your app class
|
|
28
|
+
end
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
This will hook up some Rack middleware for rotating the flash and provide a `flash` method for use in your route handlers.
|
|
29
31
|
|
|
30
32
|
See `tests.rb` for examples.
|
|
31
33
|
|
data/lib/tiny_rack_flash.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'delegate'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
class TinyRackFlash
|
|
4
4
|
|
|
5
5
|
FlashKey = 'tiny.rack.flash'.freeze
|
|
6
6
|
SessionKey = 'rack.session'.freeze
|
|
@@ -45,28 +45,24 @@ module TinyRackFlash
|
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
module Helpers
|
|
49
|
+
def flash
|
|
50
|
+
env[FlashKey] ||= begin
|
|
51
|
+
session = env[SessionKey]
|
|
52
|
+
FlashHash.new((session ? session[FlashKey] : {}))
|
|
53
|
+
end
|
|
52
54
|
end
|
|
53
55
|
end
|
|
54
|
-
|
|
55
|
-
class Middleware
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
57
|
+
def initialize(app, opts={})
|
|
58
|
+
@app, @opts = app, opts
|
|
59
|
+
yield Helpers if block_given?
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def call(env)
|
|
63
|
+
res = @app.call(env)
|
|
64
|
+
env[SessionKey][FlashKey] = env[FlashKey].next if env[FlashKey]
|
|
65
|
+
res
|
|
67
66
|
end
|
|
68
|
-
|
|
69
|
-
def self.included(app); app.use Middleware; end
|
|
70
|
-
|
|
71
67
|
|
|
72
68
|
end
|
data/tests.rb
CHANGED
|
@@ -10,7 +10,10 @@ require "cuba"
|
|
|
10
10
|
|
|
11
11
|
class SinatraApp < Sinatra::Base
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
use TinyRackFlash do |mixins|
|
|
14
|
+
include mixins
|
|
15
|
+
end
|
|
16
|
+
|
|
14
17
|
set :sessions, true
|
|
15
18
|
|
|
16
19
|
get '/' do
|
|
@@ -31,7 +34,9 @@ end
|
|
|
31
34
|
class CubaApp < Cuba
|
|
32
35
|
|
|
33
36
|
use Rack::Session::Cookie, secret: "__a_very_long_string__"
|
|
34
|
-
|
|
37
|
+
use TinyRackFlash do |mixins|
|
|
38
|
+
include mixins
|
|
39
|
+
end
|
|
35
40
|
|
|
36
41
|
define do
|
|
37
42
|
on root do
|
data/tiny-rack-flash.gemspec
CHANGED
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |spec|
|
|
6
6
|
spec.name = "tiny-rack-flash"
|
|
7
|
-
spec.version = '0.0.
|
|
7
|
+
spec.version = '0.0.2'
|
|
8
8
|
spec.authors = ["Jacob Brown"]
|
|
9
9
|
spec.email = ["j.h.brown@tcu.edu"]
|
|
10
10
|
spec.description = %q{ A tiny flash implementation for Rack apps }
|