merb_has_flash 0.9.2 → 0.9.6

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.
data/README CHANGED
@@ -11,4 +11,5 @@ Hacked together by Michael Ivey <ivey@gweezlebur.com> ... send bug
11
11
  reports and patches to him.
12
12
 
13
13
  Contributors:
14
- Tim Kofol
14
+ Tim Kofol
15
+ Shay Arnett
data/Rakefile CHANGED
@@ -1,30 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'rake/gempackagetask'
3
3
 
4
- PLUGIN = "merb_has_flash"
5
- NAME = "merb_has_flash"
6
- VERSION = "0.9.2"
7
- AUTHOR = "Michael Ivey"
8
- EMAIL = "ivey@gweezlebur.com"
9
- HOMEPAGE = "http://merb-plugins.rubyforge.org/merb_has_flash/"
10
- SUMMARY = "Merb plugin that provides a Rails-style flash"
11
-
12
- spec = Gem::Specification.new do |s|
13
- s.name = NAME
14
- s.version = VERSION
15
- s.platform = Gem::Platform::RUBY
16
- s.has_rdoc = true
17
- s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
18
- s.summary = SUMMARY
19
- s.description = s.summary
20
- s.author = AUTHOR
21
- s.email = EMAIL
22
- s.homepage = HOMEPAGE
23
- s.add_dependency('merb-core', '>= 0.9.2')
24
- s.require_path = 'lib'
25
- s.autorequire = PLUGIN
26
- s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs}/**/*")
27
- end
4
+ spec = eval(File.read('merb_has_flash.gemspec'))
28
5
 
29
6
  Rake::GemPackageTask.new(spec) do |pkg|
30
7
  pkg.gem_spec = spec
@@ -36,4 +13,4 @@ end
36
13
 
37
14
  task :release => :package do
38
15
  sh %{rubyforge add_release merb-plugins merb_has_flash #{VERSION} pkg/#{NAME}-#{VERSION}.gem}
39
- end
16
+ end
@@ -4,16 +4,18 @@ end
4
4
 
5
5
  require 'merb_has_flash/flash_hash'
6
6
 
7
+ require 'merb_has_flash/helper'
8
+ Merb::RenderMixin.send :include, MerbHasFlash::FlashHelperMixin
9
+
7
10
  require 'merb_has_flash/controller_extension'
8
11
  Merb::Controller.send :include, MerbHasFlash::ControllerExtension
9
12
 
10
- require 'merb_has_flash/helper'
11
- Merb::RenderMixin.send :include, MerbHasFlash::FlashHelperMixin
13
+
12
14
 
13
15
  module MerbHasFlash
14
16
  # The flash provides a way to pass temporary objects between actions. Anything you place in the flash will be exposed
15
17
  # to the very next action and then cleared out. This is a great way of doing notices and alerts, such as a create action
16
- # that sets <tt>flash[:notice] = "Successfully created"</tt> before redirecting to a display action that can then expose
18
+ # that sets <tt>flash[:notice] = "Successfully created"</tt> before redirecting to a display action that can then expose
17
19
  # the flash to its template. Actually, that exposure is automatically done. Example:
18
20
  #
19
21
  # class WeblogController < Merb::Controller
@@ -2,36 +2,19 @@ module MerbHasFlash
2
2
  module ControllerExtension
3
3
  def self.included(base)
4
4
  base.send :include, InstanceMethods
5
-
6
- base.class_eval {
7
- after :sweep_flash
8
- }
5
+ base.class_eval { after :sweep_flash }
9
6
  end
10
-
7
+
11
8
  module InstanceMethods
12
- # Access the contents of the flash. Use <tt>flash["notice"]</tt> to read a notice you put there or
13
- # <tt>flash["notice"] = "hello"</tt> to put a new one.
14
- # Note that if sessions are disabled only flash.now will work.
15
- def flash(refresh = false) #:doc:
16
- if !defined?(@_flash) || refresh
17
- @_flash =
18
- if session.is_a?(Hash)
19
- # don't put flash in session if disabled
20
- FlashHash.new
21
- else
22
- # otherwise, session is a CGI::Session or a TestSession
23
- # so make sure it gets retrieved from/saved to session storage after request processing
24
- session["flash"] ||= FlashHash.new
25
- end
26
- end
27
9
 
28
- @_flash
10
+ def flash(refresh = false) #:doc:
11
+ session['flash'] = FlashHash.new unless refresh || session['flash'].is_a?(FlashHash)
12
+ session['flash']
29
13
  end
30
-
31
- protected
14
+
15
+ protected
32
16
  def sweep_flash
33
- flash.sweep if request.session
34
- session["flash"] = flash
17
+ flash.sweep
35
18
  end
36
19
  end
37
20
  end
@@ -3,45 +3,55 @@ module MerbHasFlash
3
3
  def initialize(flash)
4
4
  @flash = flash
5
5
  end
6
-
7
- def []=(k, v)
8
- @flash[k] = v
9
- @flash.discard(k)
10
- v
6
+
7
+ def []=(key, val)
8
+ @flash[key] = val
9
+ @flash.discard key
10
+ val
11
11
  end
12
-
13
- def [](k)
14
- @flash[k]
12
+
13
+ def [](key)
14
+ @flash[key]
15
15
  end
16
16
  end
17
-
18
- class FlashHash < Hash
19
- def initialize #:nodoc:
20
- super
21
- @used = {}
17
+
18
+ class FlashHash
19
+ def initialize(*args) #:nodoc:
20
+ @attrs = Hash.new(*args)
21
+ @keepers = []
22
22
  end
23
-
24
- def []=(k, v) #:nodoc:
25
- keep(k)
26
- super
23
+
24
+ def []=(key, val) #:nodoc:
25
+ @attrs[key] = val
26
+ keep key
27
27
  end
28
-
29
- def update(h) #:nodoc:
30
- h.keys.each{ |k| discard(k) }
31
- super
28
+
29
+ def [](key)
30
+ @attrs[key]
32
31
  end
33
-
32
+
33
+ def update(hash) #:nodoc:
34
+ @attrs.update hash
35
+ hash.keys.each { |key| keep key }
36
+ end
37
+
34
38
  alias :merge! :update
35
-
36
- def replace(h) #:nodoc:
37
- @used = {}
38
- super
39
+
40
+ def replace(hash) #:nodoc:
41
+ @attrs.replace hash
42
+ keep # keep with no args automatically clears out unused keys and keeps all used ones.
43
+ end
44
+
45
+
46
+ def method_missing(method_name, *args) #:nodoc:
47
+ @attrs.send(method_name, *args)
39
48
  end
40
-
49
+
50
+
41
51
  # Sets a flash that will not be available to the next action, only to the current.
42
52
  #
43
53
  # flash.now[:message] = "Hello current action"
44
- #
54
+ #
45
55
  # This method enables you to use the flash as a central messaging system in your app.
46
56
  # When you need to pass an object to the next action, you use the standard flash assign (<tt>[]=</tt>).
47
57
  # When you need to pass an object to the current action, you use <tt>now</tt>, and your object will
@@ -49,53 +59,33 @@ module MerbHasFlash
49
59
  #
50
60
  # Entries set via <tt>now</tt> are accessed the same way as standard entries: <tt>flash['my-key']</tt>.
51
61
  def now
52
- FlashNow.new self
62
+ @_fn ||= FlashNow.new self # This way, a new object is not created on every "now."
53
63
  end
54
-
64
+
55
65
  # Keeps either the entire current flash or a specific flash entry available for the next action:
56
66
  #
57
67
  # flash.keep # keeps the entire flash
58
- # flash.keep(:notice) # keeps only the "notice" entry, the rest of the flash is discarded
59
- def keep(k = nil)
60
- use(k, false)
68
+ # flash.keep(:notice) # keeps only the "notice" entry
69
+ def keep(key = nil)
70
+ key.nil? ? @keepers = @attrs.keys : @keepers << key unless @keepers.include?(key)
61
71
  end
62
-
72
+
63
73
  # Marks the entire flash or a single flash entry to be discarded by the end of the current action
64
74
  #
65
- # flash.keep # keep entire flash available for the next action
66
- # flash.discard(:warning) # discard the "warning" entry (it'll still be available for the current action)
67
- def discard(k = nil)
68
- use(k)
75
+ # flash.discard # discard the entire hash (it'll still be available for the current action)
76
+ # flash.discard(:warning) # discard the "warning" entry (still available as above)
77
+ def discard(key = nil)
78
+ key.nil? ? @keepers = [] : @keepers.delete(key)
69
79
  end
70
-
71
- # Mark for removal entries that were kept, and delete unkept ones.
72
- #
80
+
81
+ # Clear the keys that are kept, and delete the ones that are currently unkept
73
82
  # This method is called automatically by filters, so you generally don't need to care about it.
74
83
  def sweep #:nodoc:
75
- keys.each do |k|
76
- unless @used[k]
77
- use(k)
78
- else
79
- delete(k)
80
- @used.delete(k)
81
- end
82
- end
83
-
84
- (@used.keys - keys).each{|k| @used.delete k } # clean up after keys that could have been left over by calling reject! or shift on the flash
84
+ @attrs.keys.each { |key| @attrs.delete key unless @keepers.include?(key) }
85
+ discard
85
86
  end
86
-
87
- private
88
- # Used internally by the <tt>keep</tt> and <tt>discard</tt> methods
89
- # use() # marks the entire flash as used
90
- # use('msg') # marks the "msg" entry as used
91
- # use(nil, false) # marks the entire flash as unused (keeps it around for one more action)
92
- # use('msg', false) # marks the "msg" entry as unused (keeps it around for one more action)
93
- def use(k=nil, v=true)
94
- unless k.nil?
95
- @used[k] = v
96
- else
97
- keys.each{|key| use key, v }
98
- end
99
- end
87
+
88
+
100
89
  end
101
- end
90
+
91
+ end
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "merb_has_flash Controller Extension" do
4
+ it "should have specs, but doesn't..."
5
+ end
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'merb_has_flash/flash_hash'
3
+
4
+ describe "merb_has_flash FlashHash" do
5
+ before(:each) do
6
+ @hash = MerbHasFlash::FlashHash.new
7
+ end
8
+
9
+ it "should not be a kind of Hash" do
10
+ # Merb 0.9.6 now transmutes all Hashes in sessions into Mashes.. destroying the functionality.
11
+ @hash.should_not be_a_kind_of(Hash)
12
+ end
13
+
14
+ it "should keep appropriate variables on sweep" do
15
+ @hash[:a] = true
16
+ @hash[:b] = false
17
+ @hash[:c] = 90928
18
+
19
+ @hash.sweep
20
+
21
+ @hash[:a].should eql(true)
22
+ @hash[:b].should eql(false)
23
+ @hash[:c].should eql(90928)
24
+ end
25
+
26
+ it "should not keep variables when using now" do
27
+ @hash.now[:a] = true
28
+ @hash[:b] = true
29
+ @hash.instance_variable_get(:@keepers).should_not include(:a)
30
+ end
31
+
32
+ it "should discard appropriate variables on sweep" do
33
+ @hash.now[:a] = true
34
+ @hash[:b] = false
35
+ @hash[:c] = 90928
36
+ @hash.discard(:c)
37
+ @hash[:d] = 'Sir, the smurfs are eating your lunch...'
38
+
39
+ @hash.sweep
40
+
41
+ @hash[:a].should be_nil
42
+ @hash[:b].should eql(false)
43
+ @hash[:c].should be_nil
44
+ @hash[:d].should eql('Sir, the smurfs are eating your lunch...')
45
+ end
46
+
47
+ end
@@ -0,0 +1,2 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
metadata CHANGED
@@ -1,48 +1,50 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb_has_flash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
- - Michael Ivey
8
- autorequire: merb_has_flash
7
+ - Michael D. Ivey
8
+ - Jeremy Nicoll
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2008-03-27 00:00:00 -05:00
13
+ date: 2008-09-10 00:00:00 -05:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: merb-core
18
+ type: :runtime
17
19
  version_requirement:
18
20
  version_requirements: !ruby/object:Gem::Requirement
19
21
  requirements:
20
- - - ">="
22
+ - - ">"
21
23
  - !ruby/object:Gem::Version
22
- version: 0.9.2
24
+ version: 0.9.0
23
25
  version:
24
- description: Merb plugin that provides a Rails-style flash
26
+ description: Rails' 'flash' session notification system ported to Merb
25
27
  email: ivey@gweezlebur.com
26
28
  executables: []
27
29
 
28
30
  extensions: []
29
31
 
30
- extra_rdoc_files:
31
- - README
32
- - LICENSE
33
- - TODO
32
+ extra_rdoc_files: []
33
+
34
34
  files:
35
35
  - LICENSE
36
- - README
37
36
  - Rakefile
37
+ - README
38
38
  - TODO
39
- - lib/merb_has_flash
39
+ - lib/merb_has_flash.rb
40
40
  - lib/merb_has_flash/controller_extension.rb
41
41
  - lib/merb_has_flash/flash_hash.rb
42
42
  - lib/merb_has_flash/helper.rb
43
- - lib/merb_has_flash.rb
44
- has_rdoc: true
45
- homepage: http://merb-plugins.rubyforge.org/merb_has_flash/
43
+ - spec/merb_has_flash/controller_extension_spec.rb
44
+ - spec/merb_has_flash/flash_hash_spec.rb
45
+ - spec/spec_helper.rb
46
+ has_rdoc: false
47
+ homepage: http://github.com/ivey/merb_has_flash
46
48
  post_install_message:
47
49
  rdoc_options: []
48
50
 
@@ -63,9 +65,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
65
  requirements: []
64
66
 
65
67
  rubyforge_project:
66
- rubygems_version: 1.0.1
68
+ rubygems_version: 1.2.0
67
69
  signing_key:
68
70
  specification_version: 2
69
- summary: Merb plugin that provides a Rails-style flash
70
- test_files: []
71
-
71
+ summary: Rails' 'flash' session notification system ported to Merb
72
+ test_files:
73
+ - spec/merb_has_flash/controller_extension_spec.rb
74
+ - spec/merb_has_flash/flash_hash_spec.rb
75
+ - spec/spec_helper.rb