cuba-flash 1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6dc35ec4afe60276331e19f317904f19cd889305
4
+ data.tar.gz: 0ab495c1d95305fcac7332ac6db8f1cc4692d109
5
+ SHA512:
6
+ metadata.gz: ba3731c181e39358acffa31c15e4f987a075b8c6d018dd89f37631108377f109cabe2a790c0666c1c9e3cb9c5fbffffc5204387c9bc46c4a4aa74e128c78d5f0
7
+ data.tar.gz: 7df56e7e183acf838c257286acc2eb84336f482e4cfa3249b9845957858b259eb485a71078037b342847ce702919bd2eabd16a83a8f4f19a98c920c6360698a8
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ tags
2
+ .ruby-version
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "cuba-flash"
5
+ s.version = "1.0"
6
+ s.summary = "A flash message helper for Cuba apps"
7
+ s.license = "MIT"
8
+ s.description = "A flash message helper for Cuba apps"
9
+ s.authors = ["Leonardo Mateo", "Lautaro Orazi"]
10
+ s.email = ["kandalf@threefunkymonkeys.com", "taro@threefunkymonkeys.com"]
11
+ s.homepage = "https://github.com/threefunkymonkeys/cuba-flash"
12
+ s.require_paths = ["lib"]
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ end
data/lib/cuba/flash.rb ADDED
@@ -0,0 +1,23 @@
1
+ class Cuba
2
+ class FlashHash < Hash
3
+ def [](key)
4
+ delete(key)
5
+ end
6
+ end
7
+
8
+ class Flash
9
+ def initialize(app, opts = {})
10
+ @app, @opts = app, opts
11
+ end
12
+
13
+ def call(env)
14
+ env['rack.session']['cuba.flash'] ||= FlashHash.new
15
+
16
+ @app.call(env)
17
+ end
18
+ end
19
+
20
+ def flash
21
+ env['rack.session']['cuba.flash'] ||= FlashHash.new
22
+ end
23
+ end
@@ -0,0 +1 @@
1
+ ruby-2.2.0@cuba-flash
@@ -0,0 +1,44 @@
1
+ require 'minitest/autorun'
2
+ require 'rack/test'
3
+ require 'cuba'
4
+ require_relative '../lib/cuba/flash'
5
+
6
+ class MiniTest::Spec
7
+ include Rack::Test::Methods
8
+
9
+ def app
10
+ Cuba.app
11
+ end
12
+ end
13
+
14
+ Cuba.use Rack::Session::Cookie, :secret => "test"
15
+ Cuba.use Cuba::Flash
16
+
17
+ describe "Cuba Flash" do
18
+ it "should show flash message" do
19
+ Cuba.define do
20
+ on get, root do
21
+ flash[:info] = "Success"
22
+ res.write flash[:info]
23
+ end
24
+ end
25
+
26
+ get "/"
27
+
28
+ assert_equal "Success", last_response.body
29
+ end
30
+
31
+ it "should not show same message twice" do
32
+ Cuba.define do
33
+ on get, root do
34
+ flash[:info] = "Success"
35
+ flash[:info]
36
+ res.write flash[:info]
37
+ end
38
+ end
39
+
40
+ get "/"
41
+
42
+ assert_equal "", last_response.body
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cuba-flash
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Leonardo Mateo
8
+ - Lautaro Orazi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-04-04 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A flash message helper for Cuba apps
15
+ email:
16
+ - kandalf@threefunkymonkeys.com
17
+ - taro@threefunkymonkeys.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".gitignore"
23
+ - cuba-flash.gemspec
24
+ - lib/cuba/flash.rb
25
+ - ruby-version.sample
26
+ - test/flash_test.rb
27
+ homepage: https://github.com/threefunkymonkeys/cuba-flash
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.4.6
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: A flash message helper for Cuba apps
51
+ test_files: []