module WebCache
Public Class Methods
cache()
click to toggle source
“interface” for “generic” cache storage (might be sqlite database or filesystem)
# File lib/webget/webcache.rb, line 55 def self.cache() @cache ||= DiskCache.new; end
cached?( url )
click to toggle source
# File lib/webget/webcache.rb, line 66 def self.cached?( url ) cache.cached?( url ); end
Also aliased as: exist?
config()
click to toggle source
# File lib/webget/webcache.rb, line 46 def self.config() @config ||= Configuration.new; end
configure() { |config| ... }
click to toggle source
lets you use
Webcache.configure do |config| config.root = './cache' end
# File lib/webget/webcache.rb, line 45 def self.configure() yield( config ); end
home()
click to toggle source
copied from props gem, see Env.home
- https://github.com/rubycoco/props/blob/master/props/lib/props/env.rb todo/fix: use original - and do NOT copy-n-paste!!! - why? why not?
# File lib/webget/webcache.rb, line 9 def self.home path = if( ENV['HOME'] || ENV['USERPROFILE'] ) ENV['HOME'] || ENV['USERPROFILE'] elsif( ENV['HOMEDRIVE'] && ENV['HOMEPATH'] ) "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}" else begin File.expand_path('~') rescue if File::ALT_SEPARATOR 'C:/' else '/' end end end ## note: use File.expand_path to "unify" path e.g ## C:\Users\roman becomes ## C:/Users/roman File.expand_path( path ) end
read( url )
click to toggle source
# File lib/webget/webcache.rb, line 71 def self.read( url ) cache.read( url ); end
read_csv( url )
click to toggle source
# File lib/webget/webcache.rb, line 73 def self.read_csv( url ) cache.read_csv( url ); end
read_json( url )
click to toggle source
# File lib/webget/webcache.rb, line 72 def self.read_json( url ) cache.read_json( url ); end
record( url, response, path: nil, encoding: 'UTF-8', format: 'html' )
click to toggle source
# File lib/webget/webcache.rb, line 57 def self.record( url, response, path: nil, encoding: 'UTF-8', format: 'html' ) cache.record( url, response, path: path, encoding: encoding, format: format ); end
root()
click to toggle source
add “high level” root convenience helpers
# File lib/webget/webcache.rb, line 50 def self.root() config.root; end
root=(value)
click to toggle source
# File lib/webget/webcache.rb, line 51 def self.root=(value) config.root = value; end
url_to_id( url )
click to toggle source
# File lib/webget/webcache.rb, line 70 def self.url_to_id( url ) cache.url_to_id( url ); end