Parent

Included Modules

Sinatra::Cookies::Jar

Attributes

options[R]

Public Class Methods

new(app) click to toggle source
# File lib/sinatra/cookies.rb, line 61
def initialize(app)
  @response_string = nil
  @response_hash   = {}
  @response        = app.response
  @request         = app.request
  @deleted         = []

  @options = {
    :path     => @request.script_name,
    :domain   => @request.host,
    :secure   => @request.secure?,
    :httponly => true
  }

  @options[:path] = '/' if @options[:path].to_s.empty?

  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 82
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 86
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 90
def []=(key, value)
  @response.set_cookie key.to_s, @options.merge(:value => value)
end
Also aliased as: store
assoc(key) click to toggle source
# File lib/sinatra/cookies.rb, line 94
def assoc(key)
  to_hash.assoc(key.to_s)
end
clear() click to toggle source
# File lib/sinatra/cookies.rb, line 98
def clear
  each_key { |k| delete(k) }
end
compare_by_identity?() click to toggle source
# File lib/sinatra/cookies.rb, line 102
def compare_by_identity?
  false
end
default() click to toggle source
# File lib/sinatra/cookies.rb, line 106
def default
  nil
end
Also aliased as: default_proc
default_proc() click to toggle source
Alias for: default
delete(key) click to toggle source
# File lib/sinatra/cookies.rb, line 112
def delete(key)
  result = self[key]
  @response.delete_cookie(key.to_s, @options)
  result
end
delete_if() click to toggle source
# File lib/sinatra/cookies.rb, line 118
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 124
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 129
def each_key(&block)
  return enum_for(__method__) unless block_given?
  to_hash.each_key(&block)
end
each_pair(&block) click to toggle source
Alias for: each
each_value(&block) click to toggle source
# File lib/sinatra/cookies.rb, line 136
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 141
def empty?
  to_hash.empty?
end
fetch(key, &block) click to toggle source
# File lib/sinatra/cookies.rb, line 145
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 151
def flatten
  to_hash.flatten
end
has_key?(key) click to toggle source
# File lib/sinatra/cookies.rb, line 155
def has_key?(key)
  response_cookies.has_key? key.to_s or request_cookies.has_key? key.to_s
end
Also aliased as: include?, member?, key?
has_value?(value) click to toggle source
# File lib/sinatra/cookies.rb, line 159
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 163
def hash
  to_hash.hash
end
include?(key) click to toggle source
Alias for: has_key?
index(value) click to toggle source
# File lib/sinatra/cookies.rb, line 170
def index(value)
  warn "Hash#index is deprecated; use Hash#key" if RUBY_VERSION > '1.9'
  key(value)
end
inspect() click to toggle source
# File lib/sinatra/cookies.rb, line 175
def inspect
  "<##{self.class}: #{to_hash.inspect[1..-2]}>"
end
invert() click to toggle source
# File lib/sinatra/cookies.rb, line 179
def invert
  to_hash.invert
end
keep_if() click to toggle source
# File lib/sinatra/cookies.rb, line 183
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 188
def key(value)
  to_hash.key(value)
end
key?(key) click to toggle source
Alias for: has_key?
keys() click to toggle source
# File lib/sinatra/cookies.rb, line 194
def keys
  to_hash.keys
end
length() click to toggle source
# File lib/sinatra/cookies.rb, line 198
def length
  to_hash.length
end
Also aliased as: size
member?(key) click to toggle source
Alias for: has_key?
merge(other, &block) click to toggle source
# File lib/sinatra/cookies.rb, line 202
def merge(other, &block)
  to_hash.merge(other, &block)
end
merge!(other) click to toggle source
# File lib/sinatra/cookies.rb, line 206
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 216
def rassoc(value)
  to_hash.rassoc(value)
end
rehash() click to toggle source
# File lib/sinatra/cookies.rb, line 220
def rehash
  response_cookies.rehash
  request_cookies.rehash
  self
end
reject(&block) click to toggle source
# File lib/sinatra/cookies.rb, line 226
def reject(&block)
  return enum_for(__method__) unless block_given?
  to_hash.reject(&block)
end
reject!() click to toggle source
Alias for: delete_if
replace(other) click to toggle source
# File lib/sinatra/cookies.rb, line 233
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 238
def select(&block)
  return enum_for(__method__) unless block_given?
  to_hash.select(&block)
end
select!() click to toggle source
Alias for: keep_if
shift() click to toggle source
# File lib/sinatra/cookies.rb, line 245
def shift
  key, value = to_hash.shift
  delete(key)
  [key, value]
end
size() click to toggle source
Alias for: length
sort(&block) click to toggle source
# File lib/sinatra/cookies.rb, line 253
def sort(&block)
  to_hash.sort(&block)
end
store(key, value) click to toggle source
Alias for: []=
to_a() click to toggle source
# File lib/sinatra/cookies.rb, line 263
def to_a
  to_hash.to_a
end
to_hash() click to toggle source
# File lib/sinatra/cookies.rb, line 259
def to_hash
  request_cookies.merge(response_cookies)
end
to_s() click to toggle source
# File lib/sinatra/cookies.rb, line 267
def to_s
  to_hash.to_s
end
update(other) click to toggle source
Alias for: merge!
value?(value) click to toggle source
Alias for: has_value?
values() click to toggle source
# File lib/sinatra/cookies.rb, line 274
def values
  to_hash.values
end
values_at(*list) click to toggle source
# File lib/sinatra/cookies.rb, line 278
def values_at(*list)
  list.map { |k| self[k] }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.