open-uri-cached 0.0.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of open-uri-cached might be problematic. Click here for more details.

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1cf2ef137bca3a2593b5adc10d8baee89ec92bd28fec595f69dde388e6fbc0d5
4
+ data.tar.gz: c22f7c6d400194f783623f3b38cb38c45b10c3c88586b9fcf866339eca1d2b13
5
+ SHA512:
6
+ metadata.gz: 5d6511c368e3d2be307f5aa9ee64b49750437e0771e5f7e0649b381d6022a20733b1e9f03bea86a388f08e3c5d243ccc2d0fd8fbb8c28a5e0b47cada6f15404a
7
+ data.tar.gz: b0848773a410b08fa05e6546b12b9316ef45658f71b0b0f4558dff734cc5bbb586a0bf80dd785571e0a6b70ffc14e8cea02b35329ece7f4d3c51f6d0715e4019
@@ -11,4 +11,10 @@ Require the library
11
11
 
12
12
  ## Configuring
13
13
 
14
- OpenURI::Cache.cache_path = '/tmp/open-uri'
14
+ `OpenURI::Cache.cache_path = '/tmp/open-uri'`
15
+
16
+ ## Invalidating
17
+
18
+ `OpenURI::Cache.invalidate('https://example.com/')`
19
+
20
+ `OpenURI::Cache.invalidate_all!`
@@ -1,5 +1,6 @@
1
- require 'open-uri'
2
1
  require 'digest/sha1'
2
+ require 'fileutils'
3
+ require 'open-uri'
3
4
  require 'yaml'
4
5
 
5
6
  module OpenURI
@@ -36,9 +37,15 @@ module OpenURI
36
37
  # TODO: head request to determine last_modified vs file modtime
37
38
 
38
39
  # Read metadata, if it exists
39
- meta = YAML::load(File.read("#{filename}.meta")) if File.exists?("#{filename}.meta")
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
40
47
 
41
- f = File.exists?(filename) ? StringIO.new(File.open(filename, "rb") { |f| f.read }) : nil
48
+ f = File.exist?(filename) ? StringIO.new(File.open(filename, "rb") { |fd| fd.read }) : nil
42
49
 
43
50
  # Add meta accessors
44
51
  if meta && f
@@ -111,6 +118,11 @@ module OpenURI
111
118
  false
112
119
  end
113
120
 
121
+ # Invalidate all caches we know about
122
+ def invalidate_all!
123
+ FileUtils.rm_r(@cache_path, force: true, secure: true)
124
+ end
125
+
114
126
  protected
115
127
  def filename_from_url(url)
116
128
  uri = URI.parse(url) # TODO: rescue here?
@@ -124,7 +136,7 @@ module OpenURI
124
136
  full.push(dir)
125
137
  dir = full.join('/')
126
138
  next if dir.to_s == ''
127
- Dir.mkdir(dir) unless File.exists?(dir)
139
+ Dir.mkdir(dir) unless File.exist?(dir)
128
140
  end
129
141
  end
130
142
  end
metadata CHANGED
@@ -1,66 +1,74 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: open-uri-cached
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 5
9
- version: 0.0.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Danial Pearce
13
- autorequire:
8
+ autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2012-01-08 00:00:00 +11:00
18
- default_executable:
19
- dependencies: []
20
-
11
+ date: 2021-12-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.10.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.10.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: webmock
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.14.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.14.0
21
41
  description: OpenURI with transparent disk caching
22
- email: rubygems@tigris.id.au
42
+ email: danial.pearce@gmail.com
23
43
  executables: []
24
-
25
44
  extensions: []
26
-
27
45
  extra_rdoc_files: []
28
-
29
- files:
30
- - README.markdown
46
+ files:
31
47
  - LICENSE
48
+ - README.md
32
49
  - lib/open-uri/cached.rb
33
- has_rdoc: true
34
- homepage: http://github.com/tigris/open-uri-cached
50
+ homepage: https://github.com/tigris/open-uri-cached
35
51
  licenses: []
36
-
37
- post_install_message:
52
+ metadata: {}
53
+ post_install_message:
38
54
  rdoc_options: []
39
-
40
- require_paths:
55
+ require_paths:
41
56
  - lib
42
- required_ruby_version: !ruby/object:Gem::Requirement
43
- none: false
44
- requirements:
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
45
59
  - - ">="
46
- - !ruby/object:Gem::Version
47
- segments:
48
- - 0
49
- version: "0"
50
- required_rubygems_version: !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
53
64
  - - ">="
54
- - !ruby/object:Gem::Version
55
- segments:
56
- - 0
57
- version: "0"
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
58
67
  requirements: []
59
-
60
- rubyforge_project:
61
- rubygems_version: 1.3.7
62
- signing_key:
63
- specification_version: 3
64
- summary: Do a lot of site scraping but take lots of attempts at parsing the content before reaching your end result? This gem is for you. But wait, there's more... Ok, no there isn't.
68
+ rubygems_version: 3.2.22
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Do a lot of site scraping but take lots of attempts at parsing the content
72
+ before reaching your end result? This gem is for you. But wait, there's more...
73
+ Ok, no there isn't.
65
74
  test_files: []
66
-