voltron-flash 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d659cb376f6d21612a62b40803e6abc7eaa21d6
4
- data.tar.gz: f57c9abb3a446e306b8831d93d15fe54d80a9d01
3
+ metadata.gz: 1f706827eaa82fc21f386839dd9b20f280573622
4
+ data.tar.gz: 6422d9fb168c0ba1e56732f56a80044706e5a8ed
5
5
  SHA512:
6
- metadata.gz: 8a00c035cf0b05afe2429df810205743912893d281aa4f2ad0514b2b321048d16063e159de4c045034a13c6dcf085af553afaa0e0e82fbd83c1593f00a5965a2
7
- data.tar.gz: 67c166c9edf0aa815e6503cfe9b3a4579cf7896a18d1b8f953760217dbecfe81f2b534c03b979229877f40aa1a71f4c0f4781a764010a0b1bf244cf15bda54b7
6
+ metadata.gz: 315ef39aaf64f42a72ef8d53612aa6fbdb3e6cbbcc25837d22dd92c0dafea867811acd3ad3584ce96bc12d5335e96238542c83e75521724d1c41405bb6e2dac7
7
+ data.tar.gz: 841e0719e3ed007b2298d058def944bf50061547e8825ee33c225c5be638200f4cde6da5cf1ac2e9e4b6d9860ff25dd64cca94429179006c993b544f3fdbb618
@@ -1,5 +1,5 @@
1
1
  module Voltron
2
2
  module Flash
3
- VERSION = "0.1.2".freeze
3
+ VERSION = "0.1.3".freeze
4
4
  end
5
5
  end
data/lib/voltron/flash.rb CHANGED
@@ -11,14 +11,22 @@ module Voltron
11
11
 
12
12
  def render(*args)
13
13
  include_flash_now
14
- super *args
14
+ super
15
+ end
16
+
17
+ def redirect_to(options={}, response_status={})
18
+ include_flash_later
19
+ super
15
20
  end
16
21
 
17
22
  def flash!(**flashes)
18
23
  flashes.symbolize_keys.each do |type,messages|
19
24
  stored_flashes[type] ||= []
20
- stored_flashes[type] << { ajax: flashes.delete(:ajax), messages: Array.wrap(messages) }
25
+ stored_flashes[type] += Array.wrap(messages)
21
26
  end
27
+
28
+ # Set the headers initially. If redirecting, they will be removed as the flash will instead be a part of `flash`
29
+ response.headers[Voltron.config.flash.header] = stored_flashes.to_json
22
30
  end
23
31
 
24
32
  private
@@ -30,31 +38,15 @@ module Voltron
30
38
  # Before rendering, include any flash messages in flash.now,
31
39
  # so they will be available when the page is rendered
32
40
  def include_flash_now
33
- flash_hash(true).each { |type,messages| flash.now[type] = messages }
41
+ stored_flashes.each { |type,messages| flash.now[type] = messages }
34
42
  end
35
43
 
36
- # If request is an ajax request, or we are redirecting, include flash messages
37
- # in the appropriate outlet, either response headers or `flash` itself
44
+ # When redirecting, remove the flash from the headers (unless ajax request), append it all to the `flash` object
38
45
  def include_flash_later
39
- if is_redirecting?
40
- flash_hash.each { |type,messages| flash[type] = messages }
41
- elsif request.xhr?
42
- response.headers[Voltron.config.flash.header] = flash_hash.to_json
43
- end
44
- end
45
-
46
- def is_redirecting?
47
- self.status == 302 || self.status == 301
48
- end
49
-
50
- def flash_hash(rendering=false)
51
- flashes = stored_flashes.map do |type,messages|
52
- { type => messages.map do |f|
53
- f[:messages] if !(f[:ajax] == false && request.xhr?) || (f[:ajax] == false && request.xhr? && rendering)
54
- end.compact.flatten
55
- }
46
+ unless request.xhr?
47
+ response.headers.except! Voltron.config.flash.header
48
+ stored_flashes.each { |type,messages| flash[type] = messages }
56
49
  end
57
- flashes.reduce(Hash.new, :merge).reject { |k,v| v.blank? || k == :ajax }
58
50
  end
59
51
 
60
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voltron-flash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hainer