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.



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

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



193
194
195
# File 'lib/action_controller/cookies.rb', line 193

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

Instance Method Details

#[](name) ⇒ Object



176
177
178
179
180
# File 'lib/action_controller/cookies.rb', line 176

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

#[]=(key, options) ⇒ Object



182
183
184
185
186
187
188
189
190
191
# File 'lib/action_controller/cookies.rb', line 182

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