Class: WebCrawler::CacheAdapter::File
- Inherits:
-
Base
- Object
- Base
- WebCrawler::CacheAdapter::File
show all
- Defined in:
- lib/web_crawler/cache_adapter/file.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#expire_within, #expired?, #prepare_response, #set
Constructor Details
#initialize(dir) ⇒ File
Returns a new instance of File.
9
10
11
|
# File 'lib/web_crawler/cache_adapter/file.rb', line 9
def initialize(dir)
@dir = Pathname.new dir
end
|
Instance Attribute Details
#dir ⇒ Object
Returns the value of attribute dir.
7
8
9
|
# File 'lib/web_crawler/cache_adapter/file.rb', line 7
def dir
@dir
end
|
Instance Method Details
#exist?(uri) ⇒ Boolean
23
24
25
|
# File 'lib/web_crawler/cache_adapter/file.rb', line 23
def exist? uri
file(uri).exist?
end
|
#expire!(response) ⇒ Object
32
33
34
|
# File 'lib/web_crawler/cache_adapter/file.rb', line 32
def expire!(response)
file(response).delete
end
|
#file(response_or_url) ⇒ Object
27
28
29
30
|
# File 'lib/web_crawler/cache_adapter/file.rb', line 27
def file(response_or_url)
url = response_or_url.url rescue response_or_url
dir.join(uri_to_filename(url))
end
|
#get(uri) ⇒ Object
17
18
19
20
21
|
# File 'lib/web_crawler/cache_adapter/file.rb', line 17
def get uri
response = read(uri)
expire!(response) if expired?(response)
response
end
|
#put(response) ⇒ Object
13
14
15
|
# File 'lib/web_crawler/cache_adapter/file.rb', line 13
def put response
response.tap { write(super) }
end
|