Class: Sinatra::Cookies::Jar
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Enumerable
#chunk, #count, #cycle, #drop, #drop_while, #each_entry, #each_with_index_with_optional_args_and_block, #each_with_object, #entries_with_optional_arguments, #find_index, #first, #flat_map, #group_by, #inject_with_symbol, #lazy, #max_by, #min_by, #minmax, #minmax_by, #none?, #one?, #reverse_each, #slice_before, #sum, #take, #take_while, #to_a_with_optional_arguments
Constructor Details
#initialize(app) ⇒ Jar
Returns a new instance of Jar.
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/vendor/sinatra-contrib-1.4.1/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
|
Instance Attribute Details
Returns the value of attribute options.
59
60
61
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 59
def options
@options
end
|
Instance Method Details
#==(other) ⇒ Object
82
83
84
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 82
def ==(other)
other.respond_to? :to_hash and to_hash == other.to_hash
end
|
86
87
88
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 86
def [](key)
response_cookies[key.to_s] || request_cookies[key.to_s]
end
|
#[]=(key, value) ⇒ Object
Also known as:
store
90
91
92
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 90
def []=(key, value)
@response.set_cookie key.to_s, @options.merge(:value => value)
end
|
#assoc(key) ⇒ Object
94
95
96
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 94
def assoc(key)
to_hash.assoc(key.to_s)
end
|
98
99
100
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 98
def clear
each_key { |k| delete(k) }
end
|
#compare_by_identity? ⇒ Boolean
102
103
104
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 102
def compare_by_identity?
false
end
|
#default ⇒ Object
Also known as:
default_proc
106
107
108
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 106
def default
nil
end
|
#delete(key) ⇒ Object
112
113
114
115
116
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 112
def delete(key)
result = self[key]
@response.delete_cookie(key.to_s, @options)
result
end
|
#delete_if ⇒ Object
Also known as:
reject!
118
119
120
121
122
|
# File 'lib/vendor/sinatra-contrib-1.4.1/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
|
#each(&block) ⇒ Object
Also known as:
each_pair
124
125
126
127
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 124
def each(&block)
return enum_for(__method__) unless block_given?
to_hash.each(&block)
end
|
#each_key(&block) ⇒ Object
129
130
131
132
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 129
def each_key(&block)
return enum_for(__method__) unless block_given?
to_hash.each_key(&block)
end
|
#each_value(&block) ⇒ Object
136
137
138
139
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 136
def each_value(&block)
return enum_for(__method__) unless block_given?
to_hash.each_value(&block)
end
|
#empty? ⇒ Boolean
141
142
143
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 141
def empty?
to_hash.empty?
end
|
#fetch(key, &block) ⇒ Object
145
146
147
148
149
|
# File 'lib/vendor/sinatra-contrib-1.4.1/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
|
151
152
153
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 151
def flatten
to_hash.flatten
end
|
#has_key?(key) ⇒ Boolean
Also known as:
include?, member?, key?
155
156
157
|
# File 'lib/vendor/sinatra-contrib-1.4.1/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
|
#has_value?(value) ⇒ Boolean
Also known as:
value?
159
160
161
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 159
def has_value?(value)
response_cookies.has_value? value or request_cookies.has_value? value
end
|
163
164
165
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 163
def hash
to_hash.hash
end
|
#index(value) ⇒ Object
170
171
172
173
|
# File 'lib/vendor/sinatra-contrib-1.4.1/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
|
175
176
177
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 175
def inspect
"<##{self.class}: #{to_hash.inspect[1..-2]}>"
end
|
179
180
181
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 179
def invert
to_hash.invert
end
|
#keep_if ⇒ Object
Also known as:
select!
183
184
185
186
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 183
def keep_if
return enum_for(__method__) unless block_given?
delete_if { |*a| not yield(*a) }
end
|
#key(value) ⇒ Object
188
189
190
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 188
def key(value)
to_hash.key(value)
end
|
194
195
196
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 194
def keys
to_hash.keys
end
|
#length ⇒ Object
Also known as:
size
198
199
200
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 198
def length
to_hash.length
end
|
#merge(other, &block) ⇒ Object
202
203
204
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 202
def merge(other, &block)
to_hash.merge(other, &block)
end
|
#merge!(other) ⇒ Object
Also known as:
update
206
207
208
209
210
211
212
213
214
|
# File 'lib/vendor/sinatra-contrib-1.4.1/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
|
#rassoc(value) ⇒ Object
216
217
218
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 216
def rassoc(value)
to_hash.rassoc(value)
end
|
220
221
222
223
224
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 220
def rehash
response_cookies.rehash
request_cookies.rehash
self
end
|
#reject(&block) ⇒ Object
226
227
228
229
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 226
def reject(&block)
return enum_for(__method__) unless block_given?
to_hash.reject(&block)
end
|
#replace(other) ⇒ Object
233
234
235
236
|
# File 'lib/vendor/sinatra-contrib-1.4.1/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) ⇒ Object
238
239
240
241
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 238
def select(&block)
return enum_for(__method__) unless block_given?
to_hash.select(&block)
end
|
245
246
247
248
249
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 245
def shift
key, value = to_hash.shift
delete(key)
[key, value]
end
|
#sort(&block) ⇒ Object
253
254
255
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 253
def sort(&block)
to_hash.sort(&block)
end
|
263
264
265
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 263
def to_a
to_hash.to_a
end
|
259
260
261
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 259
def to_hash
request_cookies.merge(response_cookies)
end
|
267
268
269
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 267
def to_s
to_hash.to_s
end
|
274
275
276
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 274
def values
to_hash.values
end
|
#values_at(*list) ⇒ Object
278
279
280
|
# File 'lib/vendor/sinatra-contrib-1.4.1/lib/sinatra/cookies.rb', line 278
def values_at(*list)
list.map { |k| self[k] }
end
|