padrino-flash 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,12 +13,29 @@ module Padrino
13
13
  @next = {}
14
14
  end
15
15
 
16
+ ###
17
+ # Returns the specified flash message
18
+ #
19
+ # @return [String]
20
+ # Flash message
21
+ #
22
+ # @example
23
+ # flash[:notice]
24
+ # # => 'Invalid login/password combination'
25
+ #
16
26
  # @since 0.1.0
17
27
  # @api public
18
28
  def [](type)
19
29
  @now[type]
20
30
  end
21
31
 
32
+ ###
33
+ # Sets the specified flash message
34
+ #
35
+ # @example
36
+ # flash[:notice] = 'Invalid login/password combination'
37
+ # flash[:notice] = :invalid_login
38
+ #
22
39
  # @since 0.1.0
23
40
  # @api public
24
41
  def []=(type, message)
@@ -26,25 +43,63 @@ module Padrino
26
43
  @next[type] = message
27
44
  end
28
45
 
46
+ ###
47
+ # Deletes the specified flash message
48
+ #
49
+ # @return [String]
50
+ # Value of the deleted flash message
51
+ #
52
+ # @example
53
+ # flash.delete :notice
54
+ #
29
55
  # @since 0.1.0
30
56
  # @api public
31
57
  def delete(type)
32
58
  @now.delete(type)
33
- self
34
59
  end
35
60
 
61
+ ###
62
+ # Returns an array of flashes that have been set
63
+ #
64
+ # @return [Array<Symbol>]
65
+ # Flashes set
66
+ #
67
+ # @example
68
+ # flash.keys
69
+ # # => [:notice]
70
+ #
36
71
  # @since 0.1.0
37
72
  # @api public
38
73
  def keys
39
74
  @now.keys
40
75
  end
41
76
 
77
+ ###
78
+ # Returns whether or not the specified flash is set
79
+ #
80
+ # @return [Boolean]
81
+ # *true* if it is, *false* otherwise
82
+ #
83
+ # @example
84
+ # flash.key?(:notice)
85
+ # # => true
86
+ #
42
87
  # @since 0.1.0
43
88
  # @api public
44
89
  def key?(type)
45
90
  @now.key?(type)
46
91
  end
92
+ alias_method :has_key?, :key?
93
+ alias_method :include?, :key?
47
94
 
95
+ ###
96
+ # Iterates through set flashes
97
+ #
98
+ # @example
99
+ # flash.each do |type, message|
100
+ # # ...
101
+ # end
102
+ #
48
103
  # @since 0.1.0
49
104
  # @api public
50
105
  def each(&block)
@@ -67,13 +122,20 @@ module Padrino
67
122
  alias_method :merge!, :update
68
123
 
69
124
  # @since 0.1.0
70
- # @api public
125
+ # @api private
71
126
  def sweep
72
127
  @now.replace(@next)
73
128
  @next = {}
74
129
  self
75
130
  end
76
131
 
132
+ ###
133
+ # Keeps the specified flash for the next request
134
+ #
135
+ # @example
136
+ # flash.keep :notice
137
+ # flash.keep
138
+ #
77
139
  # @since 0.1.0
78
140
  # @api public
79
141
  def keep(key = nil)
@@ -84,6 +146,13 @@ module Padrino
84
146
  end
85
147
  end
86
148
 
149
+ ###
150
+ # Discards the specified flash so it doesn't show up on the next request
151
+ #
152
+ # @example
153
+ # flash.discard :notice
154
+ # flash.discard
155
+ #
87
156
  # @since 0.1.0
88
157
  # @api public
89
158
  def discard(key = nil)
@@ -94,12 +163,28 @@ module Padrino
94
163
  end
95
164
  end
96
165
 
166
+ ###
167
+ # Deletes all flashes that are currently set
168
+ #
169
+ # @example
170
+ # flash.clear
171
+ #
97
172
  # @since 0.1.0
98
173
  # @api public
99
174
  def clear
100
175
  @now.clear
101
176
  end
102
177
 
178
+ ###
179
+ # Returns whether or not any flashes have been set
180
+ #
181
+ # @return [Boolean]
182
+ # *true* if flashes are set, *false* otherwise
183
+ #
184
+ # @example
185
+ # flash.empty?
186
+ # # => true
187
+ #
103
188
  # @since 0.1.0
104
189
  # @api public
105
190
  def empty?
@@ -118,36 +203,84 @@ module Padrino
118
203
  @now.to_s
119
204
  end
120
205
 
206
+ ###
207
+ # Writer for the flash trinity :error (red)
208
+ #
209
+ # @example
210
+ # flash.error = 'Something really bad happened here'
211
+ #
121
212
  # @since 0.1.0
122
213
  # @api public
123
214
  def error=(message)
124
215
  self[:error] = message
125
216
  end
126
217
 
218
+ ###
219
+ # Reader for the flash trinity :error (red)
220
+ #
221
+ # @return [String]
222
+ # Flash message
223
+ #
224
+ # @example
225
+ # flash.error
226
+ # # => 'Something really bad happened here'
227
+ #
127
228
  # @since 0.1.0
128
229
  # @api public
129
230
  def error
130
231
  self[:error]
131
232
  end
132
233
 
234
+ ###
235
+ # Writer for the flash trinity :notice (yellow)
236
+ #
237
+ # @example
238
+ # flash.notice = 'Something that needs your attention happened here'
239
+ #
133
240
  # @since 0.1.0
134
241
  # @api public
135
242
  def notice=(message)
136
243
  self[:notice] = message
137
244
  end
138
245
 
246
+ ###
247
+ # Reader for the flash trinity :notice (yellow)
248
+ #
249
+ # @return [String]
250
+ # Flash message
251
+ #
252
+ # @example
253
+ # flash.notice
254
+ # # => 'Something that needs your attention happened here'
255
+ #
139
256
  # @since 0.1.0
140
257
  # @api public
141
258
  def notice
142
259
  self[:notice]
143
260
  end
144
261
 
262
+ ###
263
+ # Writer for the flash trinity :success (green)
264
+ #
265
+ # @example
266
+ # flash.success = 'Something good happened here'
267
+ #
145
268
  # @since 0.1.0
146
269
  # @api public
147
270
  def success=(message)
148
271
  self[:success] = message
149
272
  end
150
273
 
274
+ ###
275
+ # Reader for the flash trinity :success (green)
276
+ #
277
+ # @return [String]
278
+ # Flash message
279
+ #
280
+ # @example
281
+ # flash.success
282
+ # # => 'Something good happened here'
283
+ #
151
284
  # @since 0.1.0
152
285
  # @api public
153
286
  def success
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  module Padrino
3
3
  module Flash
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.0'
5
5
  end # Flash
6
6
  end # Padrino
@@ -10,11 +10,16 @@ describe Padrino::Flash::Storage do
10
10
  flash[:two] = 'Two'
11
11
  end
12
12
 
13
- it 'can delete a single flash' do
14
- flash[:notice].should == 'Flash Notice'
15
- flash.delete :notice
16
- flash.key?(:notice).should be_false
17
- flash[:notice].should be_nil
13
+ context :delete do
14
+ it 'should remove the message from the storage hash' do
15
+ flash[:notice].should == 'Flash Notice'
16
+ flash.delete :notice
17
+ flash.key?(:notice).should be_false
18
+ end
19
+
20
+ it 'should return the value of the deleted flash' do
21
+ flash.delete(:notice).should == 'Flash Notice'
22
+ end
18
23
  end
19
24
 
20
25
  it 'can delete the entire flash' do
@@ -25,15 +30,17 @@ describe Padrino::Flash::Storage do
25
30
  flash[:success].should be_nil
26
31
  end
27
32
 
28
- it 'should set future flash messages' do
29
- flash[:future] = 'Test'
30
- flash[:future].should be_nil
31
- flash.next[:future].should == 'Test'
32
- end
33
+ context :[]= do
34
+ it 'should localize flash messages when a :symbol is used' do
35
+ flash[:localized] = :redirected
36
+ flash.next[:localized].should == 'Redirected'
37
+ end
33
38
 
34
- it 'should localize flash messages when a :symbol is used' do
35
- flash[:localized] = :redirected
36
- flash.next[:localized].should == 'Redirected'
39
+ it 'should set future flash messages' do
40
+ flash[:future] = 'Test'
41
+ flash[:future].should be_nil
42
+ flash.next[:future].should == 'Test'
43
+ end
37
44
  end
38
45
 
39
46
  it 'should allow you to set the present flash' do
@@ -68,13 +75,23 @@ describe Padrino::Flash::Storage do
68
75
  flash[:success].should_not == 'Flash Success'
69
76
  end
70
77
 
71
- it 'can iterate through flash messages' do
72
- flashes = []
73
- flash.each do |type, message|
74
- flashes << [type, message]
78
+ context :each do
79
+ it 'can iterate through flash messages' do
80
+ flashes = []
81
+ flash.each do |type, message|
82
+ flashes << [type, message]
83
+ end
84
+ flashes[0].should == [:notice, 'Flash Notice']
85
+ flashes[1].should == [:success, 'Flash Success']
86
+ end
87
+
88
+ it 'should allow enumeration' do
89
+ flashes = flash.collect do |type, message|
90
+ [type, message]
91
+ end
92
+ flashes[0].should == [:notice, 'Flash Notice']
93
+ flashes[1].should == [:success, 'Flash Success']
75
94
  end
76
- flashes[0].should == [:notice, 'Flash Notice']
77
- flashes[1].should == [:success, 'Flash Success']
78
95
  end
79
96
 
80
97
  it 'can sweep up the old to make room for the new' do
@@ -92,13 +109,30 @@ describe Padrino::Flash::Storage do
92
109
  flash[:error].should == 'Replaced'
93
110
  end
94
111
 
95
- it 'can return the existing flash keys' do
96
- flash.keys.should == [:notice, :success]
112
+ context :keys do
113
+ it 'can return the existing flash keys' do
114
+ flash.keys.should == [:notice, :success]
115
+ end
116
+
117
+ it 'should return an empty array when no flashes are set' do
118
+ flash.clear
119
+ flash.keys.should == []
120
+ end
97
121
  end
98
122
 
99
- it 'can tell you if a key is set' do
100
- flash.key?(:notice).should be_true
101
- flash.key?(:one).should be_false
123
+ context :key? do
124
+ it 'should return true when a flash is set' do
125
+ flash.key?(:notice).should be_true
126
+ end
127
+
128
+ it 'should return false when a flash is not set' do
129
+ flash.key?(:non_existent).should be_false
130
+ end
131
+
132
+ it 'should not read future flash messages' do
133
+ flash[:future] = 'Future'
134
+ flash.key?(:future).should be_false
135
+ end
102
136
  end
103
137
 
104
138
  it 'can merge flash messages' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-flash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-27 00:00:00.000000000 Z
12
+ date: 2012-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: padrino-core
16
- requirement: &15649596 !ruby/object:Gem::Requirement
16
+ requirement: &15597876 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *15649596
24
+ version_requirements: *15597876
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: padrino-helpers
27
- requirement: &15649284 !ruby/object:Gem::Requirement
27
+ requirement: &15597504 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *15649284
35
+ version_requirements: *15597504
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &15648936 !ruby/object:Gem::Requirement
38
+ requirement: &15597144 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *15648936
46
+ version_requirements: *15597144
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec-html-matchers
49
- requirement: &15648624 !ruby/object:Gem::Requirement
49
+ requirement: &15596724 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *15648624
57
+ version_requirements: *15596724
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rack-test
60
- requirement: &15648288 !ruby/object:Gem::Requirement
60
+ requirement: &15596352 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *15648288
68
+ version_requirements: *15596352
69
69
  description: A plugin for the Padrino web framework which adds support for Rails like
70
70
  flash messages
71
71
  email: