Class: ActionDispatch::Cookies::SignedCookieJar

Inherits:
CookieJar show all
Defined in:
actionpack/lib/action_dispatch/middleware/cookies.rb

Overview

:nodoc:

Constant Summary

4096
SECRET_MIN_LENGTH =

Cookies can typically store 4096 bytes. Characters

30

Constants inherited from CookieJar

CookieJar::DOMAIN_REGEXP

Instance Method Summary (collapse)

Methods inherited from CookieJar

build, #delete, #handle_options, #permanent, #signed, #write

Methods inherited from Hash

#as_json, #assert_valid_keys, #deep_merge, #deep_merge!, #diff, #encode_json, #except, #except!, #extract!, #extractable_options?, from_xml, #reverse_merge, #reverse_merge!, #slice, #slice!, #stringify_keys, #stringify_keys!, #symbolize_keys, #symbolize_keys!, #to_param, #to_xml, #with_indifferent_access

Constructor Details

- (SignedCookieJar) initialize(parent_jar, secret)

Returns a new instance of SignedCookieJar



230
231
232
233
234
# File 'actionpack/lib/action_dispatch/middleware/cookies.rb', line 230

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

- (Object) method_missing(method, *arguments, &block)



256
257
258
# File 'actionpack/lib/action_dispatch/middleware/cookies.rb', line 256

def method_missing(method, *arguments, &block)
  @parent_jar.send(method, *arguments, &block)
end

Instance Method Details

- (Object) [](name)



236
237
238
239
240
241
242
# File 'actionpack/lib/action_dispatch/middleware/cookies.rb', line 236

def [](name)
  if signed_message = @parent_jar[name]
    @verifier.verify(signed_message)
  end
rescue ActiveSupport::MessageVerifier::InvalidSignature
  nil
end

- (Object) []=(key, options)

Raises:



244
245
246
247
248
249
250
251
252
253
254
# File 'actionpack/lib/action_dispatch/middleware/cookies.rb', line 244

def []=(key, options)
  if options.is_a?(Hash)
    options.symbolize_keys!
    options[:value] = @verifier.generate(options[:value])
  else
    options = { :value => @verifier.generate(options) }
  end

  raise CookieOverflow if options[:value].size > MAX_COOKIE_SIZE
  @parent_jar[key] = options
end