open-uri-cached 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of open-uri-cached might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +15 -3
- data/lib/open-uri/cached.rb +3 -8
- metadata +7 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 349b8c42b059c7fd2cf0284c5df387559ba97ddccea7e4c1b9fe0f93f030af1b
|
4
|
+
data.tar.gz: bf8e5c09b35ccd42f04a37d791340e9532892380eacea4e8d7657ab301a1894c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c66cd1f8fc5a320ece25968fb8651100dd2011b4eadb3ee5c99c24273e192f423a78b3f00019366ff8ca6e8b960ddd90024a92603bb942fea6289321290b6295
|
7
|
+
data.tar.gz: bb4bbcfdd49782212169c7372156455f725de04ae56c451eb20427fb3da4e82bf306b61b7b4347fabb945c64ece16e66b70bf426a3bc10feee96c688b22f3681
|
data/README.md
CHANGED
@@ -6,15 +6,27 @@ Carelessly make OpenURI requests without getting hate mail.
|
|
6
6
|
|
7
7
|
Require the library
|
8
8
|
|
9
|
+
```ruby
|
9
10
|
require 'open-uri/cached'
|
10
11
|
open('http://www.someone-that-hates-being-scraped.com').read
|
12
|
+
```
|
11
13
|
|
12
14
|
## Configuring
|
13
15
|
|
14
|
-
|
16
|
+
If you're not super pumped about reading files from `/tmp`, you can configure the cache path:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
OpenURI::Cache.cache_path = '/tmp/open-uri'
|
20
|
+
```
|
15
21
|
|
16
22
|
## Invalidating
|
17
23
|
|
18
|
-
|
24
|
+
They say cache invalidation is hard, but not really:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# Invalidate a single URL
|
28
|
+
OpenURI::Cache.invalidate('https://example.com/')
|
19
29
|
|
20
|
-
|
30
|
+
# Invalidate everything
|
31
|
+
OpenURI::Cache.invalidate_all!
|
32
|
+
```
|
data/lib/open-uri/cached.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'digest/sha1'
|
2
2
|
require 'fileutils'
|
3
3
|
require 'open-uri'
|
4
|
+
require 'securerandom'
|
4
5
|
require 'yaml'
|
5
6
|
|
6
7
|
module OpenURI
|
@@ -23,7 +24,7 @@ module OpenURI
|
|
23
24
|
end
|
24
25
|
|
25
26
|
class Cache
|
26
|
-
@cache_path = "/tmp/open-uri-#{
|
27
|
+
@cache_path = "/tmp/open-uri-#{SecureRandom.uuid}"
|
27
28
|
|
28
29
|
class << self
|
29
30
|
attr_accessor :cache_path
|
@@ -37,13 +38,7 @@ module OpenURI
|
|
37
38
|
# TODO: head request to determine last_modified vs file modtime
|
38
39
|
|
39
40
|
# Read metadata, if it exists
|
40
|
-
if File.exist?("#{filename}.meta")
|
41
|
-
if YAML.respond_to?(:unsafe_load)
|
42
|
-
meta = YAML.unsafe_load(File.read("#{filename}.meta"))
|
43
|
-
else
|
44
|
-
meta = YAML.load(File.read("#{filename}.meta"))
|
45
|
-
end
|
46
|
-
end
|
41
|
+
meta = YAML.unsafe_load(File.read("#{filename}.meta")) if File.exist?("#{filename}.meta")
|
47
42
|
|
48
43
|
f = File.exist?(filename) ? StringIO.new(File.open(filename, "rb") { |fd| fd.read }) : nil
|
49
44
|
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open-uri-cached
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danial Pearce
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rspec
|
@@ -16,28 +15,28 @@ dependencies:
|
|
16
15
|
requirements:
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.10
|
18
|
+
version: '3.10'
|
20
19
|
type: :development
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
23
|
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.10
|
25
|
+
version: '3.10'
|
27
26
|
- !ruby/object:Gem::Dependency
|
28
27
|
name: webmock
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
30
|
- - "~>"
|
32
31
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.14
|
32
|
+
version: '3.14'
|
34
33
|
type: :development
|
35
34
|
prerelease: false
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
37
36
|
requirements:
|
38
37
|
- - "~>"
|
39
38
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.14
|
39
|
+
version: '3.14'
|
41
40
|
description: OpenURI with transparent disk caching
|
42
41
|
email: danial.pearce@gmail.com
|
43
42
|
executables: []
|
@@ -50,7 +49,6 @@ files:
|
|
50
49
|
homepage: https://github.com/tigris/open-uri-cached
|
51
50
|
licenses: []
|
52
51
|
metadata: {}
|
53
|
-
post_install_message:
|
54
52
|
rdoc_options: []
|
55
53
|
require_paths:
|
56
54
|
- lib
|
@@ -65,8 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
63
|
- !ruby/object:Gem::Version
|
66
64
|
version: '0'
|
67
65
|
requirements: []
|
68
|
-
rubygems_version: 3.
|
69
|
-
signing_key:
|
66
|
+
rubygems_version: 3.6.9
|
70
67
|
specification_version: 4
|
71
68
|
summary: Do a lot of site scraping but take lots of attempts at parsing the content
|
72
69
|
before reaching your end result? This gem is for you. But wait, there's more...
|