Class: Sinatra::Cookies::Jar
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
Enumerable
|
|
Inherits: | Object |
Defined in: | sinatra-contrib/lib/sinatra/cookies.rb |
Class Method Summary
- .new(app) ⇒ Jar constructor
Instance Attribute Summary
- #compare_by_identity? ⇒ Boolean readonly
- #empty? ⇒ Boolean readonly
- #options readonly
Instance Method Summary
- #==(other)
- #[](key)
- #[]=(key, value) (also: #store)
- #assoc(key)
- #clear
- #default (also: #default_proc)
-
#default_proc
Alias for #default.
- #delete(key)
- #delete_if (also: #reject!)
- #each(&block) (also: #each_pair)
- #each_key(&block)
-
#each_pair(&block)
Alias for #each.
- #each_value(&block)
- #fetch(key, &block)
- #flatten
- #has_key?(key) ⇒ Boolean (also: #include?, #member?, #key?)
- #has_value?(value) ⇒ Boolean (also: #value?)
- #hash
-
#include?(key)
Alias for #has_key?.
- #inspect
- #invert
- #keep_if (also: #select!, #select!)
- #key(value)
-
#key?(key)
Alias for #has_key?.
- #keys
- #length (also: #size)
-
#member?(key)
Alias for #has_key?.
- #merge(other, &block)
- #merge!(other) (also: #update)
- #rassoc(value)
- #rehash
- #reject(&block)
-
#reject!
Alias for #delete_if.
- #replace(other)
- #select(&block)
-
#select!
Alias for #keep_if.
- #set(key, options = {})
- #shift
-
#size
Alias for #length.
- #sort(&block)
-
#store(key, value)
Alias for #[]=.
- #to_a
- #to_hash
- #to_s
-
#update(other)
Alias for #merge!.
-
#value?(value)
Alias for #has_value?.
- #values
- #values_at(*list)
- #deleted private
- #parse_response private
- #request_cookies private
- #response_cookies private
- #warn(message) private
Constructor Details
.new(app) ⇒ Jar
# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 62
def initialize(app) @response_array = 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 } return unless app.settings.respond_to? : @options.merge! app.settings. end
Instance Attribute Details
#compare_by_identity? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 103
def compare_by_identity? false end
#empty? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 146
def empty? to_hash.empty? end
#options (readonly)
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 60
attr_reader :
Instance Method Details
#==(other)
[ GitHub ]#[](key)
[ GitHub ]#[]=(key, value) Also known as: #store
[ GitHub ]#assoc(key)
[ GitHub ]#clear
[ GitHub ]#default Also known as: #default_proc
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 107
def default nil end
#default_proc
Alias for #default.
# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 111
alias default_proc default
#delete(key)
[ GitHub ]#delete_if Also known as: #reject!
[ GitHub ]#deleted (private)
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 301
def deleted parse_response @deleted end
#each(&block) Also known as: #each_pair
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 126
def each(&block) return enum_for(__method__) unless block_given? to_hash.each(&block) end
#each_key(&block)
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 132
def each_key(&block) return enum_for(__method__) unless block_given? to_hash.each_key(&block) end
#each_pair(&block)
Alias for #each.
# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 138
alias each_pair each
#each_value(&block)
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 140
def each_value(&block) return enum_for(__method__) unless block_given? to_hash.each_value(&block) end
#fetch(key, &block)
[ GitHub ]#flatten
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 157
def flatten to_hash.flatten end
#has_key?(key) ⇒ Boolean
Also known as: #include?, #member?, #key?
#has_value?(value) ⇒ Boolean
Also known as: #value?
#hash
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 170
def hash to_hash.hash end
#include?(key)
Alias for #has_key?.
# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 174
alias include? has_key?
#inspect
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 177
def inspect "<##{self.class}: #{to_hash.inspect[1..-2]}>" end
#invert
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 182
def invert to_hash.invert end
#keep_if Also known as: #select!, #select!
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 187
def keep_if return enum_for(__method__) unless block_given? delete_if { |*a| !yield(*a) } end
#key(value)
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 193
def key(value) to_hash.key(value) end
#key?(key)
Alias for #has_key?.
# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 197
alias key? has_key?
#keys
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 199
def keys to_hash.keys end
#length Also known as: #size
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 203
def length to_hash.length end
#member?(key)
Alias for #has_key?.
# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 175
alias member? has_key?
#merge(other, &block)
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 207
def merge(other, &block) to_hash.merge(other, &block) end
#merge!(other) Also known as: #update
[ GitHub ]#parse_response (private)
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 311
def parse_response = Array(@response['Set-Cookie']) return if @response_array == hash = {} .each 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_array = end
#rassoc(value)
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 221
def rassoc(value) to_hash.rassoc(value) end
#rehash
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 225
def rehash .rehash .rehash self end
#reject(&block)
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 231
def reject(&block) return enum_for(__method__) unless block_given? to_hash.reject(&block) end
#reject!
Alias for #delete_if.
# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 237
alias reject! delete_if
#replace(other)
[ GitHub ]#request_cookies (private)
[ GitHub ]#response_cookies (private)
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 306
def parse_response @response_hash end
#select(&block)
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 244
def select(&block) return enum_for(__method__) unless block_given? to_hash.select(&block) end
#select!
Alias for #keep_if.
# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 250
alias select! keep_if if Hash.method_defined? :select!
#set(key, options = {})
[ GitHub ]#shift
[ GitHub ]#size
Alias for #length.
# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 262
alias size length
#sort(&block)
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 265
def sort(&block) to_hash.sort(&block) end
#store(key, value)
Alias for #[]=.
# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 270
alias store []=
#to_a
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 276
def to_a to_hash.to_a end
#to_hash
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 272
def to_hash .merge( ) end
#to_s
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 280
def to_s to_hash.to_s end
#update(other)
Alias for #merge!.
# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 284
alias update merge!
#value?(value)
Alias for #has_value?.
# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 285
alias value? has_value?
#values
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 287
def values to_hash.values end
#values_at(*list)
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 291
def values_at(*list) list.map { |k| self[k] } end
#warn(message) (private)
[ GitHub ]# File 'sinatra-contrib/lib/sinatra/cookies.rb', line 297
def warn( ) super "#{caller.first[/^[^:]:\d+:/]} warning: #{}" end