Class: Crawlr::CookieJar

Inherits:
Object
  • Object
show all
Defined in:
lib/crawlr/cookie_jar.rb

Overview

A thread-safe wrapper around the HTTP::CookieJar class

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initializeCookieJar

Returns a new instance of CookieJar.

Since:

  • 0.1.0



8
9
10
11
# File 'lib/crawlr/cookie_jar.rb', line 8

def initialize
  @jar = HTTP::CookieJar.new
  @lock = Concurrent::ReadWriteLock.new
end

Instance Method Details

#add(cookie) ⇒ Object

Since:

  • 0.1.0



13
14
15
# File 'lib/crawlr/cookie_jar.rb', line 13

def add(cookie)
  @lock.with_write_lock { @jar.add(cookie) }
end

#cookies(uri) ⇒ Object

Since:

  • 0.1.0



17
18
19
# File 'lib/crawlr/cookie_jar.rb', line 17

def cookies(uri)
  @lock.with_read_lock { @jar.cookies(uri) }
end