diff options
author | Julian Vargas <julianvargasalvarez@gmail.com> | 2013-05-12 15:04:01 -0500 |
---|---|---|
committer | Julian Vargas <julianvargasalvarez@gmail.com> | 2013-05-12 16:33:45 -0500 |
commit | c43ca06ca091fc09e2c86bb051ac92b648f12b64 (patch) | |
tree | 0e13c8f14d9ebb1c1f8cae1dba4f35fe02099d48 | |
parent | 2519fb0e6d468b45e6d12157d436540c9ef080a0 (diff) | |
download | rails-c43ca06ca091fc09e2c86bb051ac92b648f12b64.tar.gz rails-c43ca06ca091fc09e2c86bb051ac92b648f12b64.tar.bz2 rails-c43ca06ca091fc09e2c86bb051ac92b648f12b64.zip |
Code cleanup for ActionDispatch::Flash#call
The nested `if` was replaced by using `presence` which takes account for
the given hash when it is `nil` or when it is empty. The `else` was
removed because what it was doing was to assign to `env[KEY]` the
value it already had.
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/flash.rb | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/flash.rb b/actionpack/lib/action_dispatch/middleware/flash.rb index 7e56feb90a..f8f9cf7c9f 100644 --- a/actionpack/lib/action_dispatch/middleware/flash.rb +++ b/actionpack/lib/action_dispatch/middleware/flash.rb @@ -243,15 +243,9 @@ module ActionDispatch session = Request::Session.find(env) || {} flash_hash = env[KEY] - if flash_hash - if !flash_hash.empty? || session.key?('flash') - session["flash"] = flash_hash.to_session_value - new_hash = flash_hash.dup - else - new_hash = flash_hash - end - - env[KEY] = new_hash + if flash_hash.present? || session.key?('flash') + session["flash"] = flash_hash.to_session_value + env[KEY] = flash_hash.dup end if (!session.respond_to?(:loaded?) || session.loaded?) && # (reset_session uses {}, which doesn't implement #loaded?) |