Class: RubyForge::CookieManager
- Defined in:
- lib/gems/rubyforge-1.0.1/lib/rubyforge/cookie_manager.rb
Instance Attribute Summary collapse
-
#cookies_file ⇒ Object
Returns the value of attribute cookies_file.
Class Method Summary collapse
Instance Method Summary collapse
- #[](uri) ⇒ Object
- #add(uri, cookie) ⇒ Object
- #clean_stale_cookies ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(cookies_file = nil) ⇒ CookieManager
constructor
A new instance of CookieManager.
- #save! ⇒ Object
Constructor Details
#initialize(cookies_file = nil) ⇒ CookieManager
Returns a new instance of CookieManager.
12 13 14 15 16 17 |
# File 'lib/gems/rubyforge-1.0.1/lib/rubyforge/cookie_manager.rb', line 12 def initialize( = nil) @jar = Hash.new { |hash,domain_name| hash[domain_name.downcase] = {} } @cookies_file = end |
Instance Attribute Details
#cookies_file ⇒ Object
Returns the value of attribute cookies_file.
11 12 13 |
# File 'lib/gems/rubyforge-1.0.1/lib/rubyforge/cookie_manager.rb', line 11 def @cookies_file end |
Class Method Details
.load(path) ⇒ Object
4 5 6 7 8 |
# File 'lib/gems/rubyforge-1.0.1/lib/rubyforge/cookie_manager.rb', line 4 def load(path) cm = YAML.load_file(path) rescue CookieManager.new(path) cm = CookieManager.new(path) unless cm.is_a?(CookieManager) cm. end |
Instance Method Details
#[](uri) ⇒ Object
19 20 21 22 23 |
# File 'lib/gems/rubyforge-1.0.1/lib/rubyforge/cookie_manager.rb', line 19 def [](uri) # FIXME we need to do more matching on hostname.... This is not # bulletproof @jar[uri.host.downcase] end |
#add(uri, cookie) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/gems/rubyforge-1.0.1/lib/rubyforge/cookie_manager.rb', line 35 def add(uri, ) no_dot_domain = .domain.gsub(/^\./, '') return unless uri.host =~ /#{no_dot_domain}$/i @jar[no_dot_domain][.name] = end |
#clean_stale_cookies ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/gems/rubyforge-1.0.1/lib/rubyforge/cookie_manager.rb', line 42 def @jar.each do |domain, | .each do |name, | .delete(name) if .expires < Time.now end end self end |
#empty? ⇒ Boolean
25 26 27 |
# File 'lib/gems/rubyforge-1.0.1/lib/rubyforge/cookie_manager.rb', line 25 def empty? @jar.empty? || @jar.all? { |k,v| v.empty? } end |
#save! ⇒ Object
29 30 31 32 33 |
# File 'lib/gems/rubyforge-1.0.1/lib/rubyforge/cookie_manager.rb', line 29 def save! File.open(@cookies_file, 'wb') { |f| f.write(YAML.dump(self)) } end |