sinatra-flash 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,6 @@ This is an implementation of show-'em-once 'flash' messages for the [Sinatra][1]
5
5
  * Simplicity (less than 50 significant lines of code)
6
6
  * Implements the documented [behavior][3] and [public API][4] of the Rails flash that many developers are used to
7
7
  * Acts entirely like a hash, including iterations and merging
8
- * Zero configuration for a Sinatra 'classic' app -- it'll even turn sessions on if you didn't already
9
8
  * Optional multiple named flash collections, each with their own message hash, so that different embedded applications can access different sets of messages
10
9
  * An HTML helper for displaying flash messages with CSS styling
11
10
  * Verbose documentation in [YARD][5] format
@@ -21,12 +20,14 @@ You should know this part:
21
20
 
22
21
  (Or `sudo gem install` if you're the last person on Earth who isn't using [RVM][6] yet.)
23
22
 
24
- If you're developing a Sinatra ['classic'][7] application, then all you need to do is require the library:
23
+ If you're developing a Sinatra ['classic'][7] application, then all you need to do is enable sessions and require the library:
25
24
 
26
25
  # blah_app.rb
27
26
  require 'sinatra'
28
27
  require 'sinatra/flash'
29
28
 
29
+ enable :sessions
30
+
30
31
  post '/blah' do
31
32
  # This message won't be seen until the NEXT Web request that accesses the flash collection
32
33
  flash[:blah] = "You were feeling blah at #{Time.now}."
@@ -42,6 +43,7 @@ If you're using the [Sinatra::Base][7] style, you also need to register the exte
42
43
  require 'sinatra/flash'
43
44
 
44
45
  class BlehApp < Sinatra::Base
46
+ enable :sessions
45
47
  register Sinatra::Flash
46
48
 
47
49
  get '/bleh' do
@@ -111,7 +113,9 @@ These convenience methods allow you to modify the standard rotation cycle, and a
111
113
  flash.sweep # Rotates the flash manually, discarding _now_ and moving _next_ into its place
112
114
 
113
115
  ### Sessions
114
- The basic _concept_ of flash messages relies on having an active session for your application. Sinatra::Flash is built on the assumption that Sinatra's `session` helper points to something useful, and ensures that it does. If you've already set up Rack::Session::Cookie or done `enable sessions` or whatever, that session will be used. If you haven't, the `after` hook will enable sessions on your behalf using Sinatra's defaults. You'll probably get better results by configuring it yourself.
116
+ The basic _concept_ of flash messages relies on having an active session for your application. Sinatra::Flash is built on the assumption that Sinatra's `session` helper points to something that will persist beyond the current request. You are responsible for ensuring that it does. No other assumptions are made about the session -- you can use any [session strategy][17] you like.
117
+
118
+ (**Note:** Early versions of this extension attempted to detect the absence of a session and create one for you at the last moment. Thanks to [rkh][15] for [pointing out][16] that this is unreliable in Sinatra. You'll have to be a grownup now )
115
119
 
116
120
  ### Scoped Flash
117
121
  If one flash collection isn't exciting enough for your application stack, you can have multiple sets of flash messages scoped by a symbol. Each has its own lifecycle and will _not_ be rotated by any Web request that ignores it.
@@ -155,3 +159,6 @@ This project is licensed under the **Don't Be a Dick License**, version 0.2, and
155
159
  [12]: http://github.com/SFEley/sinatra-flash/blob/master/LICENSE.markdown
156
160
  [13]: http://dbad-license.org
157
161
  [14]: http://github.com/SFEley/sinatra-sessionography
162
+ [15]: http://github.com/rkh
163
+ [16]: http://github.com/SFEley/sinatra-flash/issues/issue/1
164
+ [17]: http://www.sinatrarb.com/faq.html#sessions
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -12,10 +12,7 @@ module Sinatra
12
12
 
13
13
  # This callback rotates any flash structure we referenced, placing the 'next' hash into the session
14
14
  # for the next request.
15
- app.after do
16
- set :sessions, true unless session # If you do not have a session, one will be appointed for you by the court.
17
- @flash.each{|key, flash| session[key] = @flash[key].next} if @flash
18
- end
15
+ app.after {@flash.each{|key, flash| session[key] = @flash[key].next} if @flash}
19
16
  end
20
17
 
21
18
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sinatra-flash}
8
- s.version = "0.2.1"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Stephen Eley"]
12
- s.date = %q{2010-04-29}
12
+ s.date = %q{2010-05-02}
13
13
  s.description = %q{A Sinatra extension for setting and showing Rails-like flash messages. This extension improves on the Rack::Flash gem by being simpler to use, providing a full range of hash operations (including iterating through various flash keys, testing the size of the hash, etc.), and offering a 'styled_flash' view helper to render the entire flash hash with sensible CSS classes. The downside is reduced flexibility -- these methods will *only* work in Sinatra.}
14
14
  s.email = %q{sfeley@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 1
9
- version: 0.2.1
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Stephen Eley
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-29 00:00:00 -04:00
17
+ date: 2010-05-02 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency