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.

Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -3
  3. data/lib/open-uri/cached.rb +3 -8
  4. metadata +7 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cf2ef137bca3a2593b5adc10d8baee89ec92bd28fec595f69dde388e6fbc0d5
4
- data.tar.gz: c22f7c6d400194f783623f3b38cb38c45b10c3c88586b9fcf866339eca1d2b13
3
+ metadata.gz: 349b8c42b059c7fd2cf0284c5df387559ba97ddccea7e4c1b9fe0f93f030af1b
4
+ data.tar.gz: bf8e5c09b35ccd42f04a37d791340e9532892380eacea4e8d7657ab301a1894c
5
5
  SHA512:
6
- metadata.gz: 5d6511c368e3d2be307f5aa9ee64b49750437e0771e5f7e0649b381d6022a20733b1e9f03bea86a388f08e3c5d243ccc2d0fd8fbb8c28a5e0b47cada6f15404a
7
- data.tar.gz: b0848773a410b08fa05e6546b12b9316ef45658f71b0b0f4558dff734cc5bbb586a0bf80dd785571e0a6b70ffc14e8cea02b35329ece7f4d3c51f6d0715e4019
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
- `OpenURI::Cache.cache_path = '/tmp/open-uri'`
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
- `OpenURI::Cache.invalidate('https://example.com/')`
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
- `OpenURI::Cache.invalidate_all!`
30
+ # Invalidate everything
31
+ OpenURI::Cache.invalidate_all!
32
+ ```
@@ -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-#{Process.uid}"
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: 1.0.0
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: 2021-12-28 00:00:00.000000000 Z
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.0
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.0
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.0
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.0
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.2.22
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...