Class: ActionController::SignedCookieJar

Inherits:
CookieJar show all
Defined in:
lib/action_controller/cookies.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from CookieJar

#controller

Instance Method Summary collapse

Methods inherited from CookieJar

#delete, #permanent, #signed

Constructor Details

#initialize(parent_jar) ⇒ SignedCookieJar

Returns a new instance of SignedCookieJar.



161
162
163
164
165
166
167
168
# File 'lib/action_controller/cookies.rb', line 161

def initialize(parent_jar)
  unless parent_jar.controller.class.cookie_verifier_secret
    raise "You must set ActionController::Base.cookie_verifier_secret to use signed cookies"
  end

  @parent_jar = parent_jar
  @verifier = ActiveSupport::MessageVerifier.new(@parent_jar.controller.class.cookie_verifier_secret)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *arguments, &block) ⇒ Object



187
188
189
# File 'lib/action_controller/cookies.rb', line 187

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

Instance Method Details

#[](name) ⇒ Object



170
171
172
173
174
# File 'lib/action_controller/cookies.rb', line 170

def [](name)
  if value = @parent_jar[name]
    @verifier.verify(value)
  end
end

#[]=(key, options) ⇒ Object



176
177
178
179
180
181
182
183
184
185
# File 'lib/action_controller/cookies.rb', line 176

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