Class: Sinatra::Cookies::Jar
- Inherits:
-
Object
- Object
- Sinatra::Cookies::Jar
- Includes:
- Enumerable
- Defined in:
- lib/sinatra/cookies.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object (also: #store)
- #assoc(key) ⇒ Object
- #clear ⇒ Object
- #compare_by_identity? ⇒ Boolean
- #default ⇒ Object (also: #default_proc)
- #delete(key) ⇒ Object
- #delete_if ⇒ Object (also: #reject!)
- #each(&block) ⇒ Object (also: #each_pair)
- #each_key(&block) ⇒ Object
- #each_value(&block) ⇒ Object
- #empty? ⇒ Boolean
- #fetch(key, &block) ⇒ Object
- #flatten ⇒ Object
- #has_key?(key) ⇒ Boolean (also: #include?, #member?, #key?)
- #has_value?(value) ⇒ Boolean (also: #value?)
- #hash ⇒ Object
- #index(value) ⇒ Object
-
#initialize(app) ⇒ Jar
constructor
A new instance of Jar.
- #inspect ⇒ Object
- #invert ⇒ Object
- #keep_if ⇒ Object (also: #select!)
- #key(value) ⇒ Object
- #keys ⇒ Object
- #length ⇒ Object (also: #size)
- #merge(other, &block) ⇒ Object
- #merge!(other) ⇒ Object (also: #update)
- #rassoc(value) ⇒ Object
- #rehash ⇒ Object
- #reject(&block) ⇒ Object
- #replace(other) ⇒ Object
- #select(&block) ⇒ Object
- #set(key, options = {}) ⇒ Object
- #shift ⇒ Object
- #sort(&block) ⇒ Object
- #to_a ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
- #values ⇒ Object
- #values_at(*list) ⇒ Object
Constructor Details
#initialize(app) ⇒ Jar
Returns a new instance of Jar.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# 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. end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
58 59 60 |
# File 'lib/sinatra/cookies.rb', line 58 def @options end |
Instance Method Details
#==(other) ⇒ Object
79 80 81 |
# File 'lib/sinatra/cookies.rb', line 79 def ==(other) other.respond_to? :to_hash and to_hash == other.to_hash end |
#[](key) ⇒ Object
83 84 85 |
# File 'lib/sinatra/cookies.rb', line 83 def [](key) [key.to_s] || [key.to_s] end |
#[]=(key, value) ⇒ Object Also known as: store
87 88 89 |
# File 'lib/sinatra/cookies.rb', line 87 def []=(key, value) set(key, value: value) end |
#assoc(key) ⇒ Object
91 92 93 |
# File 'lib/sinatra/cookies.rb', line 91 def assoc(key) to_hash.assoc(key.to_s) end |
#clear ⇒ Object
95 96 97 |
# File 'lib/sinatra/cookies.rb', line 95 def clear each_key { |k| delete(k) } end |
#compare_by_identity? ⇒ Boolean
99 100 101 |
# File 'lib/sinatra/cookies.rb', line 99 def compare_by_identity? false end |
#default ⇒ Object Also known as: default_proc
103 104 105 |
# File 'lib/sinatra/cookies.rb', line 103 def default nil end |
#delete(key) ⇒ Object
109 110 111 112 113 |
# File 'lib/sinatra/cookies.rb', line 109 def delete(key) result = self[key] @response.(key.to_s, @options) result end |
#delete_if ⇒ Object Also known as: reject!
115 116 117 118 119 |
# 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 |
#each(&block) ⇒ Object Also known as: each_pair
121 122 123 124 |
# File 'lib/sinatra/cookies.rb', line 121 def each(&block) return enum_for(__method__) unless block_given? to_hash.each(&block) end |
#each_key(&block) ⇒ Object
126 127 128 129 |
# 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) ⇒ Object
133 134 135 136 |
# 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? ⇒ Boolean
138 139 140 |
# File 'lib/sinatra/cookies.rb', line 138 def empty? to_hash.empty? end |
#fetch(key, &block) ⇒ Object
142 143 144 145 146 |
# File 'lib/sinatra/cookies.rb', line 142 def fetch(key, &block) .fetch(key.to_s) do .fetch(key.to_s, &block) end end |
#flatten ⇒ Object
148 149 150 |
# File 'lib/sinatra/cookies.rb', line 148 def flatten to_hash.flatten end |
#has_key?(key) ⇒ Boolean Also known as: include?, member?, key?
152 153 154 |
# File 'lib/sinatra/cookies.rb', line 152 def has_key?(key) .has_key? key.to_s or .has_key? key.to_s end |
#has_value?(value) ⇒ Boolean Also known as: value?
156 157 158 |
# File 'lib/sinatra/cookies.rb', line 156 def has_value?(value) .has_value? value or .has_value? value end |
#hash ⇒ Object
160 161 162 |
# File 'lib/sinatra/cookies.rb', line 160 def hash to_hash.hash end |
#index(value) ⇒ Object
167 168 169 170 |
# File 'lib/sinatra/cookies.rb', line 167 def index(value) warn "Hash#index is deprecated; use Hash#key" key(value) end |
#inspect ⇒ Object
172 173 174 |
# File 'lib/sinatra/cookies.rb', line 172 def inspect "<##{self.class}: #{to_hash.inspect[1..-2]}>" end |
#invert ⇒ Object
176 177 178 |
# File 'lib/sinatra/cookies.rb', line 176 def invert to_hash.invert end |
#keep_if ⇒ Object Also known as: select!
180 181 182 183 |
# File 'lib/sinatra/cookies.rb', line 180 def keep_if return enum_for(__method__) unless block_given? delete_if { |*a| not yield(*a) } end |
#key(value) ⇒ Object
185 186 187 |
# File 'lib/sinatra/cookies.rb', line 185 def key(value) to_hash.key(value) end |
#keys ⇒ Object
191 192 193 |
# File 'lib/sinatra/cookies.rb', line 191 def keys to_hash.keys end |
#length ⇒ Object Also known as: size
195 196 197 |
# File 'lib/sinatra/cookies.rb', line 195 def length to_hash.length end |
#merge(other, &block) ⇒ Object
199 200 201 |
# File 'lib/sinatra/cookies.rb', line 199 def merge(other, &block) to_hash.merge(other, &block) end |
#merge!(other) ⇒ Object Also known as: update
203 204 205 206 207 208 209 210 211 |
# 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 |
#rassoc(value) ⇒ Object
213 214 215 |
# File 'lib/sinatra/cookies.rb', line 213 def rassoc(value) to_hash.rassoc(value) end |
#rehash ⇒ Object
217 218 219 220 221 |
# File 'lib/sinatra/cookies.rb', line 217 def rehash .rehash .rehash self end |
#reject(&block) ⇒ Object
223 224 225 226 |
# File 'lib/sinatra/cookies.rb', line 223 def reject(&block) return enum_for(__method__) unless block_given? to_hash.reject(&block) end |
#replace(other) ⇒ Object
230 231 232 233 |
# 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) ⇒ Object
235 236 237 238 |
# 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 = {}) ⇒ Object
242 243 244 |
# File 'lib/sinatra/cookies.rb', line 242 def set(key, = {}) @response. key.to_s, @options.merge() end |
#shift ⇒ Object
246 247 248 249 250 |
# File 'lib/sinatra/cookies.rb', line 246 def shift key, value = to_hash.shift delete(key) [key, value] end |
#sort(&block) ⇒ Object
254 255 256 |
# File 'lib/sinatra/cookies.rb', line 254 def sort(&block) to_hash.sort(&block) end |
#to_a ⇒ Object
264 265 266 |
# File 'lib/sinatra/cookies.rb', line 264 def to_a to_hash.to_a end |
#to_hash ⇒ Object
260 261 262 |
# File 'lib/sinatra/cookies.rb', line 260 def to_hash .merge() end |
#to_s ⇒ Object
268 269 270 |
# File 'lib/sinatra/cookies.rb', line 268 def to_s to_hash.to_s end |
#values ⇒ Object
275 276 277 |
# File 'lib/sinatra/cookies.rb', line 275 def values to_hash.values end |
#values_at(*list) ⇒ Object
279 280 281 |
# File 'lib/sinatra/cookies.rb', line 279 def values_at(*list) list.map { |k| self[k] } end |