lhc 6.0.1 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhc/interceptors/caching.rb +3 -1
- data/lib/lhc/response.rb +4 -1
- data/lib/lhc/version.rb +1 -1
- data/spec/interceptors/caching/main_spec.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7b186ab553693a0c1b20fba140fce7ebc27dd04
|
4
|
+
data.tar.gz: b59c6f79a6c4433838bcde9c02b8a011458d1a3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a887d6528be9aa62b548a9a558bea5ae0df4a34689f8233181b05537e596310fa1716e946ed5817734ca91e6da61dcb10887e42a32a6e21bf4491340ea455002
|
7
|
+
data.tar.gz: fdd5ce8c809b8f8240ac6e8bbca2509ee05f0d45ef8801c9dfd82c6289af0f08e2c70eafc57206c67710ba84a4935128497440d08ccd2f9a8146238b01597d05
|
@@ -34,7 +34,9 @@ class LHC::Caching < LHC::Interceptor
|
|
34
34
|
# converts json we read from the cache to an LHC::Response object
|
35
35
|
def from_cache(request, data)
|
36
36
|
raw = Typhoeus::Response.new(data)
|
37
|
-
|
37
|
+
response = LHC::Response.new(raw, request, from_cache: true)
|
38
|
+
request.response = response
|
39
|
+
response
|
38
40
|
end
|
39
41
|
|
40
42
|
# converts a LHC::Response object to json, we store in the cache
|
data/lib/lhc/response.rb
CHANGED
@@ -7,14 +7,17 @@ class LHC::Response
|
|
7
7
|
autoload :Data, 'lhc/response/data'
|
8
8
|
|
9
9
|
attr_accessor :request, :body_replacement
|
10
|
+
attr_reader :from_cache
|
10
11
|
|
11
12
|
delegate :effective_url, :code, :headers, :options, :mock, :success?, to: :raw
|
13
|
+
alias from_cache? from_cache
|
12
14
|
|
13
15
|
# A response is initalized with the underlying raw response (typhoeus in our case)
|
14
16
|
# and the associated request.
|
15
|
-
def initialize(raw, request)
|
17
|
+
def initialize(raw, request, from_cache: false)
|
16
18
|
self.request = request
|
17
19
|
self.raw = raw
|
20
|
+
@from_cache = from_cache
|
18
21
|
end
|
19
22
|
|
20
23
|
def data
|
data/lib/lhc/version.rb
CHANGED
@@ -59,4 +59,13 @@ describe LHC::Caching do
|
|
59
59
|
expect(Rails.cache).to receive(:write).once
|
60
60
|
LHC.get(:local)
|
61
61
|
end
|
62
|
+
|
63
|
+
it 'marks response not from cache as not served from cache and from cache as served from cache' do
|
64
|
+
stub
|
65
|
+
LHC.config.endpoint(:local, 'http://local.ch', cache: true, cache_expires_in: 5.minutes)
|
66
|
+
original_response = LHC.get(:local)
|
67
|
+
cached_response = LHC.get(:local)
|
68
|
+
expect(original_response.from_cache?).to eq false
|
69
|
+
expect(cached_response.from_cache?).to eq true
|
70
|
+
end
|
62
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0
|
4
|
+
version: 6.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhc/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|