lib/merb-flash.rb in teamon-merb-flash-0.1.2 vs lib/merb-flash.rb in teamon-merb-flash-0.1.3
- old
+ new
@@ -3,9 +3,50 @@
# Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
Merb::Plugins.config[:merb_flash] = {}
Merb::BootLoader.before_app_loads do
- require 'merb-flash/request_controller.rb'
+ class Merb::Request
+ def message
+ @_message ||= {}
+ end
+
+ def message=(msg)
+ @_message = msg
+ end
+ end
+
+ module Merb::RedirectWithSessionFlash
+ def redirect(url, opts = {})
+ if opts[:message]
+ msg = opts.delete(:message)
+ unless msg.is_a?(Hash)
+ if msg.is_a?(String)
+ msg = Mash.new(:notice => msg)
+ else
+ raise ArgumentError
+ end
+ end
+ session[:flash] = msg
+ end
+
+ super
+ end
+ end
+
+ class Merb::Controller
+ override! :redirect
+ include Merb::RedirectWithSessionFlash
+
+ before :process_flash
+
+ protected
+
+ def process_flash
+ request.message = session[:flash]
+ session[:flash] = {}
+ end
+ end
+
end
end
\ No newline at end of file