lhc 6.0.1 → 6.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80f34ead28fd17bf1a2a18669ec7b4b178787cb1
4
- data.tar.gz: 5bba3b84203f5cf382b4f2e3309de667c614e711
3
+ metadata.gz: a7b186ab553693a0c1b20fba140fce7ebc27dd04
4
+ data.tar.gz: b59c6f79a6c4433838bcde9c02b8a011458d1a3b
5
5
  SHA512:
6
- metadata.gz: a3f6b087c8e00c7650ec6e5ce730448f19da76c8b214cbd446b39202d9a83492566bfd8bdace3e1f513523b1a6aa29f0cd45902412c597c2d4643f84c29eeb15
7
- data.tar.gz: 4c9a4d449d165c901687cad7f7167a5bae4bf98f4753ae1d71bd88dd345b961e6b692818d934c56f700e3d818e86f011b149d9d36dd5e4cb67398ca5b1c1aceb
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
- request.response = LHC::Response.new(raw, request)
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
@@ -1,3 +1,3 @@
1
1
  module LHC
2
- VERSION ||= "6.0.1"
2
+ VERSION ||= "6.1.0"
3
3
  end
@@ -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.1
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-28 00:00:00.000000000 Z
11
+ date: 2017-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus