Skip to content

Commit

Permalink
remove more nils
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Dec 17, 2019
1 parent 511f809 commit 7237b66
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
11 changes: 6 additions & 5 deletions lib/rack/session/abstract/id.rb
Expand Up @@ -16,6 +16,7 @@ module Session

class NullSessionId
def empty?; true; end
def nil?; true; end
end

module Abstract
Expand Down Expand Up @@ -51,7 +52,7 @@ def id
else
@id = @store.send(:extract_session_id, @env)
end
@id || NullSessionId.new
@id || raise
end

def options
Expand Down Expand Up @@ -89,7 +90,7 @@ def clear

def destroy
clear
@id = @store.send(:destroy_session, @env, id, options)
@id = @store.send(:destroy_session, @env, id, options) || raise
end

def to_hash
Expand Down Expand Up @@ -271,7 +272,7 @@ def prepare_session(env)
def load_session(env)
sid = current_session_id(env)
sid, session = get_session(env, sid)
[sid, session || {}]
[sid || NullSessionId.new, session || {}]
end

# Extract session id from request object.
Expand All @@ -280,7 +281,7 @@ def extract_session_id(env)
request = Rack::Request.new(env)
sid = request.cookies[@key]
sid ||= request.params[@key] unless @cookie_only
sid
sid || NullSessionId.new
end

# Returns the current session id from the SessionHash.
Expand Down Expand Up @@ -337,7 +338,7 @@ def commit_session(env, status, headers, body)

if options[:drop] || options[:renew]
session_id = destroy_session(env, session.id || generate_sid, options)
return [status, headers, body] unless session_id
return if session_id.nil?
end

return [status, headers, body] unless commit_session?(env, session, options)
Expand Down
6 changes: 5 additions & 1 deletion lib/rack/session/cookie.rb
Expand Up @@ -169,7 +169,11 @@ def set_session(env, session_id, session, options)

def destroy_session(env, session_id, options)
# Nothing to do here, data is in the client
generate_sid unless options[:drop]
if options[:drop]
NullSessionId.new
else
generate_sid
end
end

def digest_match?(data, digest)
Expand Down
6 changes: 5 additions & 1 deletion lib/rack/session/pool.rb
Expand Up @@ -61,7 +61,11 @@ def set_session(env, session_id, new_session, options)
def destroy_session(env, session_id, options)
with_lock(env) do
@pool.delete(session_id)
generate_sid unless options[:drop]
if options[:drop]
NullSessionId.new
else
generate_sid
end
end
end

Expand Down

0 comments on commit 7237b66

Please sign in to comment.