json_vat 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a6e91c0929c693ba81cdd950d28c34648671d3dd
4
- data.tar.gz: 51d688b813adea233b3534415cf3826fa83f0f2a
2
+ SHA256:
3
+ metadata.gz: 2ca5c52dda18223f56393356d1ad1eda0d4425bbaf2bae85daeeff0863174055
4
+ data.tar.gz: e45f077ac28441ce041c19c2a64d14aa3d29e46a48fb39c02099c66585a0eb1f
5
5
  SHA512:
6
- metadata.gz: 6bf4023b4c57fe9cbaf87f1424f775dc7514e81dd6f3c293b66d0581952fdc277e211f7a5361398d2ea751e23be88e1a5570a1efc6b987aef1138dde2bdaee48
7
- data.tar.gz: 68be36f8498fa19967176ec0decb514f43fe95a9151cedf03cf19e77d93d38a3c3454929ec9094c298e42796fa647acea5797e85a36ed6e9186a0c723028895d
6
+ metadata.gz: ebcb858786085bf077319ed44fd940362990f9630fd8d39a975453835c5bcfe386cf58f13aa131ef44800531bdff7076451ed74fa71b2e2bee144121f87d0dfc
7
+ data.tar.gz: 396f98fa18d34b9246eec7cda8a00373863e1ba59b579e15537ef0905d27a09f87404e353144c5f87d986691da0c3567a5422abc4e288e1b6bcac78cc199743f
@@ -42,12 +42,24 @@ module JSONVAT
42
42
  end
43
43
  end
44
44
 
45
- def rates
46
- @rates ||= JSON.parse(self.rates_through_cache)['rates'].map do |country|
45
+ def load_rates
46
+ JSON.parse(self.rates_through_cache)['rates'].map do |country|
47
47
  JSONVAT::Country.new(country)
48
48
  end
49
49
  end
50
50
 
51
+ def reload_rates?
52
+ !self.perform_caching? || (self.perform_caching? && self.cache_backend.invalid?)
53
+ end
54
+
55
+ def rates
56
+ if reload_rates?
57
+ @rates = load_rates
58
+ else
59
+ @rates
60
+ end
61
+ end
62
+
51
63
  def country(country)
52
64
  code = country.to_s.upcase
53
65
 
@@ -61,7 +73,6 @@ module JSONVAT
61
73
  def [](country)
62
74
  country(country)
63
75
  end
64
-
65
76
  end
66
77
 
67
78
  end
@@ -17,5 +17,23 @@ module JSONVAT
17
17
  File.open(self.path, 'w') { |f| f.write(data) }
18
18
  end
19
19
 
20
+ def invalid?
21
+ modified_time = current_modified_time
22
+
23
+ if modified_time != @last_modified_time
24
+ @last_modified_time = modified_time
25
+ true
26
+ else
27
+ false
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def current_modified_time
34
+ File.stat(path).mtime.to_i
35
+ rescue Errno::ENOENT
36
+ 0
37
+ end
20
38
  end
21
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_vat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-09 00:00:00.000000000 Z
11
+ date: 2018-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  version: '0'
57
57
  requirements: []
58
58
  rubyforge_project:
59
- rubygems_version: 2.4.5
59
+ rubygems_version: 2.7.4
60
60
  signing_key:
61
61
  specification_version: 4
62
62
  summary: A client library for jsonvat.com