class Sinatra::Cookies::Jar
Attributes
options[R]
Public Class Methods
new(app)
click to toggle source
# File lib/sinatra/cookies.rb, line 60 def initialize(app) @response_string = nil @response_hash = {} @response = app.response @request = app.request @deleted = [] @options = { :path => @request.script_name.to_s.empty? ? '/' : @request.script_name, :domain => @request.host == 'localhost' ? nil : @request.host, :secure => @request.secure?, :httponly => true } if app.settings.respond_to? :cookie_options @options.merge! app.settings.cookie_options end end
Public Instance Methods
==(other)
click to toggle source
# File lib/sinatra/cookies.rb, line 79 def ==(other) other.respond_to? :to_hash and to_hash == other.to_hash end
[](key)
click to toggle source
# File lib/sinatra/cookies.rb, line 83 def [](key) response_cookies[key.to_s] || request_cookies[key.to_s] end
[]=(key, value)
click to toggle source
# File lib/sinatra/cookies.rb, line 87 def []=(key, value) set(key, value: value) end
Also aliased as: store
assoc(key)
click to toggle source
# File lib/sinatra/cookies.rb, line 91 def assoc(key) to_hash.assoc(key.to_s) end
clear()
click to toggle source
# File lib/sinatra/cookies.rb, line 95 def clear each_key { |k| delete(k) } end
compare_by_identity?()
click to toggle source
# File lib/sinatra/cookies.rb, line 99 def compare_by_identity? false end
default()
click to toggle source
# File lib/sinatra/cookies.rb, line 103 def default nil end
Also aliased as: default_proc
delete(key)
click to toggle source
# File lib/sinatra/cookies.rb, line 109 def delete(key) result = self[key] @response.delete_cookie(key.to_s, @options) result end
delete_if() { |k, v| ... }
click to toggle source
# File lib/sinatra/cookies.rb, line 115 def delete_if return enum_for(__method__) unless block_given? each { |k, v| delete(k) if yield(k, v) } self end
Also aliased as: reject!
each(&block)
click to toggle source
# File lib/sinatra/cookies.rb, line 121 def each(&block) return enum_for(__method__) unless block_given? to_hash.each(&block) end
Also aliased as: each_pair
each_key(&block)
click to toggle source
# File lib/sinatra/cookies.rb, line 126 def each_key(&block) return enum_for(__method__) unless block_given? to_hash.each_key(&block) end
each_value(&block)
click to toggle source
# File lib/sinatra/cookies.rb, line 133 def each_value(&block) return enum_for(__method__) unless block_given? to_hash.each_value(&block) end
empty?()
click to toggle source
# File lib/sinatra/cookies.rb, line 138 def empty? to_hash.empty? end
fetch(key, &block)
click to toggle source
# File lib/sinatra/cookies.rb, line 142 def fetch(key, &block) response_cookies.fetch(key.to_s) do request_cookies.fetch(key.to_s, &block) end end
flatten()
click to toggle source
# File lib/sinatra/cookies.rb, line 148 def flatten to_hash.flatten end
has_key?(key)
click to toggle source
# File lib/sinatra/cookies.rb, line 152 def has_key?(key) response_cookies.has_key? key.to_s or request_cookies.has_key? key.to_s end
has_value?(value)
click to toggle source
# File lib/sinatra/cookies.rb, line 156 def has_value?(value) response_cookies.has_value? value or request_cookies.has_value? value end
Also aliased as: value?
hash()
click to toggle source
# File lib/sinatra/cookies.rb, line 160 def hash to_hash.hash end
index(value)
click to toggle source
# File lib/sinatra/cookies.rb, line 167 def index(value) warn "Hash#index is deprecated; use Hash#key" key(value) end
inspect()
click to toggle source
# File lib/sinatra/cookies.rb, line 172 def inspect "<##{self.class}: #{to_hash.inspect[1..-2]}>" end
invert()
click to toggle source
# File lib/sinatra/cookies.rb, line 176 def invert to_hash.invert end
keep_if() { |*a| ... }
click to toggle source
# File lib/sinatra/cookies.rb, line 180 def keep_if return enum_for(__method__) unless block_given? delete_if { |*a| not yield(*a) } end
Also aliased as: select!
key(value)
click to toggle source
# File lib/sinatra/cookies.rb, line 185 def key(value) to_hash.key(value) end
keys()
click to toggle source
# File lib/sinatra/cookies.rb, line 191 def keys to_hash.keys end
length()
click to toggle source
# File lib/sinatra/cookies.rb, line 195 def length to_hash.length end
Also aliased as: size
merge(other, &block)
click to toggle source
# File lib/sinatra/cookies.rb, line 199 def merge(other, &block) to_hash.merge(other, &block) end
merge!(other) { |key, self, value| ... }
click to toggle source
# File lib/sinatra/cookies.rb, line 203 def merge!(other) other.each_pair do |key, value| if block_given? and include? key self[key] = yield(key.to_s, self[key], value) else self[key] = value end end end
Also aliased as: update
rassoc(value)
click to toggle source
# File lib/sinatra/cookies.rb, line 213 def rassoc(value) to_hash.rassoc(value) end
rehash()
click to toggle source
# File lib/sinatra/cookies.rb, line 217 def rehash response_cookies.rehash request_cookies.rehash self end
reject(&block)
click to toggle source
# File lib/sinatra/cookies.rb, line 223 def reject(&block) return enum_for(__method__) unless block_given? to_hash.reject(&block) end
replace(other)
click to toggle source
# File lib/sinatra/cookies.rb, line 230 def replace(other) select! { |k, v| other.include?(k) or other.include?(k.to_s) } merge! other end
select(&block)
click to toggle source
# File lib/sinatra/cookies.rb, line 235 def select(&block) return enum_for(__method__) unless block_given? to_hash.select(&block) end
set(key, options = {})
click to toggle source
# File lib/sinatra/cookies.rb, line 242 def set(key, options = {}) @response.set_cookie key.to_s, @options.merge(options) end
shift()
click to toggle source
# File lib/sinatra/cookies.rb, line 246 def shift key, value = to_hash.shift delete(key) [key, value] end
sort(&block)
click to toggle source
# File lib/sinatra/cookies.rb, line 254 def sort(&block) to_hash.sort(&block) end
to_a()
click to toggle source
# File lib/sinatra/cookies.rb, line 264 def to_a to_hash.to_a end
to_hash()
click to toggle source
# File lib/sinatra/cookies.rb, line 260 def to_hash request_cookies.merge(response_cookies) end
to_s()
click to toggle source
# File lib/sinatra/cookies.rb, line 268 def to_s to_hash.to_s end
values()
click to toggle source
# File lib/sinatra/cookies.rb, line 275 def values to_hash.values end
values_at(*list)
click to toggle source
# File lib/sinatra/cookies.rb, line 279 def values_at(*list) list.map { |k| self[k] } end
Private Instance Methods
deleted()
click to toggle source
# File lib/sinatra/cookies.rb, line 289 def deleted parse_response @deleted end
parse_response()
click to toggle source
# File lib/sinatra/cookies.rb, line 299 def parse_response string = @response['Set-Cookie'] return if @response_string == string hash = {} string.each_line do |line| key, value = line.split(';', 2).first.to_s.split('=', 2) next if key.nil? key = Rack::Utils.unescape(key) if line =~ /expires=Thu, 01[-\s]Jan[-\s]1970/ @deleted << key else @deleted.delete key hash[key] = value end end @response_hash.replace hash @response_string = string end
warn(message)
click to toggle source
Calls superclass method
Object#warn
# File lib/sinatra/cookies.rb, line 285 def warn(message) super "#{caller.first[/^[^:]:\d+:/]} warning: #{message}" end