Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(session) compose session hash #12

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/action-controller/session.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "random"
require "./session/message_verifier"
require "./session/message_encryptor"

class ActionController::Session < Hash(String, String | Int64 | Float64 | Bool)
class ActionController::Session
NEVER = 622_080_000 # (~20 years in seconds)
# Cookies can typically store 4096 bytes.
MAX_COOKIE_SIZE = 4096
Expand All @@ -22,10 +22,11 @@ class ActionController::Session < Hash(String, String | Int64 | Float64 | Bool)
getter modified : Bool
property domain : String?
@encoder : MessageEncryptor | MessageVerifier
@store : Hash(String, String | Int64 | Float64 | Bool)

def initialize
super
forward_missing_to @store

def initialize
@modified = false
@existing = false
@domain = settings.domain
Expand All @@ -35,6 +36,8 @@ class ActionController::Session < Hash(String, String | Int64 | Float64 | Bool)
else
@encoder = MessageVerifier.new(settings.secret)
end

@store = {} of String => String | Int64 | Float64 | Bool
end

def self.from_cookies(cookies)
Expand Down Expand Up @@ -82,30 +85,30 @@ class ActionController::Session < Hash(String, String | Int64 | Float64 | Bool)
if value.nil?
delete(key)
else
super(key, value)
@store[key] = value
@modified = true
end
value
end

def clear
@modified = true if @existing
super
@store.clear
end

def delete(key)
@modified = true
super(key)
@store.delete(key)
end

def delete(key, &block)
@modified = true
super(key, &block)
@store.delete(key, &block)
end

def delete_if(&block)
@modified = true
super(&block)
@store.delete_if(&block)
end

def touch
Expand Down