Class: ActionDispatch::Cookies::SignedCookieJar
- Defined in:
- lib/action_dispatch/middleware/cookies.rb
Overview
:nodoc:
Constant Summary collapse
- MAX_COOKIE_SIZE =
Cookies can typically store 4096 bytes.
4096
- SECRET_MIN_LENGTH =
Characters
30
Constants inherited from CookieJar
Instance Attribute Summary
Attributes inherited from CookieJar
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(key, options) ⇒ Object
-
#initialize(parent_jar, secret) ⇒ SignedCookieJar
constructor
A new instance of SignedCookieJar.
- #method_missing(method, *arguments, &block) ⇒ Object
Methods inherited from CookieJar
build, #close!, #delete, #handle_options, #key?, #permanent, #signed, #update, #write
Constructor Details
#initialize(parent_jar, secret) ⇒ SignedCookieJar
Returns a new instance of SignedCookieJar.
267 268 269 270 271 |
# File 'lib/action_dispatch/middleware/cookies.rb', line 267 def initialize(parent_jar, secret) ensure_secret_secure(secret) @parent_jar = parent_jar @verifier = ActiveSupport::MessageVerifier.new(secret) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
294 295 296 |
# File 'lib/action_dispatch/middleware/cookies.rb', line 294 def method_missing(method, *arguments, &block) @parent_jar.send(method, *arguments, &block) end |
Instance Method Details
#[](name) ⇒ Object
273 274 275 276 277 278 279 |
# File 'lib/action_dispatch/middleware/cookies.rb', line 273 def [](name) if = @parent_jar[name] @verifier.verify() end rescue ActiveSupport::MessageVerifier::InvalidSignature nil end |
#[]=(key, options) ⇒ Object
281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/action_dispatch/middleware/cookies.rb', line 281 def []=(key, ) raise ClosedError, :cookies if closed? if .is_a?(Hash) .symbolize_keys! [:value] = @verifier.generate([:value]) else = { :value => @verifier.generate() } end raise CookieOverflow if [:value].size > MAX_COOKIE_SIZE @parent_jar[key] = end |