disk_store 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -16
- data/disk_store.gemspec +0 -3
- data/lib/disk_store/eviction_strategies/lru.rb +2 -5
- data/lib/disk_store/reaper.rb +1 -1
- data/lib/disk_store/version.rb +1 -1
- data/spec/disk_store_spec.rb +3 -17
- data/spec/spec_helper.rb +1 -21
- metadata +2 -46
- data/spec/cassettes/DiskStore/web_resources/should_cache_the_result_of_a_web_resource_in_a_file.json +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b80a1438fb5454793cd77e6fa2371638c6055664
|
4
|
+
data.tar.gz: 4c015900c8c3f0db8e7ecd47aab6300ef4348b4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e8c657344f7039344dd09019d44de1d5f75750ea87f29c5fb49f8d16340cba53b6c407db96fcd614bf9676445e2fe9cde2b89fb96bfae2c0a0feccf1e94c98b
|
7
|
+
data.tar.gz: 158f6cedb964548dd86bc52b7bbe52e1cc4ac00325a54b3e313f74f73b86da3cd9577938e532b5c4b003d5245cd8b21947fed7ebed768ddd6b2ac15195b91d03
|
data/Gemfile.lock
CHANGED
@@ -1,38 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
disk_store (0.2.
|
4
|
+
disk_store (0.2.2)
|
5
5
|
rake
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
addressable (2.3.5)
|
11
|
-
crack (0.4.1)
|
12
|
-
safe_yaml (~> 0.9.0)
|
13
10
|
diff-lcs (1.2.5)
|
14
|
-
|
15
|
-
rake (10.3.1)
|
11
|
+
rake (10.3.2)
|
16
12
|
rspec (2.14.1)
|
17
13
|
rspec-core (~> 2.14.0)
|
18
14
|
rspec-expectations (~> 2.14.0)
|
19
15
|
rspec-mocks (~> 2.14.0)
|
20
|
-
rspec-core (2.14.
|
16
|
+
rspec-core (2.14.8)
|
21
17
|
rspec-expectations (2.14.5)
|
22
18
|
diff-lcs (>= 1.1.3, < 2.0)
|
23
|
-
rspec-mocks (2.14.
|
24
|
-
safe_yaml (0.9.7)
|
25
|
-
vcr (2.8.0)
|
26
|
-
webmock (1.13.0)
|
27
|
-
addressable (>= 2.2.7)
|
28
|
-
crack (>= 0.3.2)
|
19
|
+
rspec-mocks (2.14.6)
|
29
20
|
|
30
21
|
PLATFORMS
|
31
22
|
ruby
|
32
23
|
|
33
24
|
DEPENDENCIES
|
34
25
|
disk_store!
|
35
|
-
multi_json
|
36
26
|
rspec
|
37
|
-
vcr
|
38
|
-
webmock
|
data/disk_store.gemspec
CHANGED
@@ -22,8 +22,5 @@ Gem::Specification.new do |gem|
|
|
22
22
|
gem.add_dependency "rake"
|
23
23
|
|
24
24
|
gem.test_files = Dir.glob("spec/**/*")
|
25
|
-
gem.add_development_dependency "multi_json"
|
26
25
|
gem.add_development_dependency "rspec"
|
27
|
-
gem.add_development_dependency "vcr"
|
28
|
-
gem.add_development_dependency "webmock"
|
29
26
|
end
|
@@ -5,11 +5,8 @@ class DiskStore
|
|
5
5
|
# Collect and sort files based on last access time
|
6
6
|
sorted_files = files
|
7
7
|
.map { |file|
|
8
|
-
|
9
|
-
|
10
|
-
data = { path: file, last_fetch: fd.atime, size: fd.size }
|
11
|
-
}.close
|
12
|
-
data
|
8
|
+
st = File.stat(file)
|
9
|
+
{ path: file, last_fetch: st.atime, size: st.size }
|
13
10
|
}
|
14
11
|
.sort { |a, b| a[:last_fetch] <=> b[:last_fetch] } # Oldest first
|
15
12
|
|
data/lib/disk_store/reaper.rb
CHANGED
data/lib/disk_store/version.rb
CHANGED
data/spec/disk_store_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe DiskStore do
|
4
4
|
let(:cache) { DiskStore.new @tmpdir }
|
5
|
-
let(:file_contents) {
|
5
|
+
let(:file_contents) { SecureRandom.random_bytes(8192) }
|
6
6
|
let(:file) { Tempfile.new("My Temp File.psd") }
|
7
7
|
let(:key) { "doge" }
|
8
8
|
|
@@ -14,6 +14,7 @@ describe DiskStore do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
before(:each) do
|
17
|
+
file.binmode
|
17
18
|
file.write file_contents
|
18
19
|
file.flush
|
19
20
|
end
|
@@ -44,7 +45,7 @@ describe DiskStore do
|
|
44
45
|
}.to change{ Dir[File.join(@tmpdir, "**/*")].size }.by(3)
|
45
46
|
|
46
47
|
file_path = Dir[File.join(@tmpdir, "**/*")].last
|
47
|
-
expect(File.
|
48
|
+
expect(File.binread(file_path)).to eq file_contents
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
@@ -66,19 +67,4 @@ describe DiskStore do
|
|
66
67
|
expect(cache.exist?(key)).to be_false
|
67
68
|
end
|
68
69
|
end
|
69
|
-
|
70
|
-
context "web resources", :vcr do
|
71
|
-
let(:url) { "http://media.giphy.com/media/KXD1pSzGb3Khi/giphy.gif" }
|
72
|
-
let(:key) { "lolololol" }
|
73
|
-
|
74
|
-
it "should cache the result of a web resource in a file" do
|
75
|
-
expect(cache.exist?(key)).to be_false
|
76
|
-
|
77
|
-
cache.fetch(key) do
|
78
|
-
open(url)
|
79
|
-
end
|
80
|
-
|
81
|
-
expect(cache.read(key).read).to eq open(url).read
|
82
|
-
end
|
83
|
-
end
|
84
70
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,32 +1,12 @@
|
|
1
1
|
require File.expand_path './lib/disk_store'
|
2
2
|
require 'rspec'
|
3
|
+
require 'securerandom'
|
3
4
|
require 'tempfile'
|
4
5
|
require 'tmpdir'
|
5
|
-
require 'vcr'
|
6
|
-
|
7
|
-
VCR.configure do |c|
|
8
|
-
c.configure_rspec_metadata!
|
9
|
-
|
10
|
-
c.default_cassette_options = {
|
11
|
-
serialize_with: :json,
|
12
|
-
preserve_exact_body_bytes: true,
|
13
|
-
decode_compressed_response: true,
|
14
|
-
match_requests_on: [:method]
|
15
|
-
}
|
16
|
-
|
17
|
-
c.cassette_library_dir = 'spec/cassettes'
|
18
|
-
c.hook_into :webmock
|
19
|
-
c.ignore_localhost = true
|
20
|
-
end
|
21
6
|
|
22
7
|
RSpec.configure do |config|
|
23
8
|
config.color_enabled = true
|
24
9
|
config.tty = true
|
25
10
|
|
26
11
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
27
|
-
|
28
|
-
config.around(:each, :vcr) do |example|
|
29
|
-
name = example.metadata[:full_description].gsub(/\//, "_").split(/\s+/, 2).join("/").gsub(/[^\w\/]+/, "_").downcase
|
30
|
-
VCR.use_cassette(name) { example.call }
|
31
|
-
end
|
32
12
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: disk_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Sutton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: multi_json
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rspec
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,34 +38,6 @@ dependencies:
|
|
52
38
|
- - '>='
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: vcr
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '>='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: webmock
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - '>='
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - '>='
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
41
|
description: Cache files the smart way.
|
84
42
|
email:
|
85
43
|
- kelly@layervault.com
|
@@ -98,7 +56,6 @@ files:
|
|
98
56
|
- lib/disk_store/eviction_strategies/lru.rb
|
99
57
|
- lib/disk_store/reaper.rb
|
100
58
|
- lib/disk_store/version.rb
|
101
|
-
- spec/cassettes/DiskStore/web_resources/should_cache_the_result_of_a_web_resource_in_a_file.json
|
102
59
|
- spec/disk_store_spec.rb
|
103
60
|
- spec/reaper_spec.rb
|
104
61
|
- spec/spec_helper.rb
|
@@ -127,7 +84,6 @@ signing_key:
|
|
127
84
|
specification_version: 4
|
128
85
|
summary: Cache fiels the smart way.
|
129
86
|
test_files:
|
130
|
-
- spec/cassettes/DiskStore/web_resources/should_cache_the_result_of_a_web_resource_in_a_file.json
|
131
87
|
- spec/disk_store_spec.rb
|
132
88
|
- spec/reaper_spec.rb
|
133
89
|
- spec/spec_helper.rb
|