vaccination-characteristics 1.1.1 → 1.2.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
  SHA256:
3
- metadata.gz: dc749136cf31028d6cd64677724c126612fdec3b4f00c15e267cd164ee7e9a62
4
- data.tar.gz: 522f8d90b2495b59a1032d67e379c1dbbff119008e91ac4d27683e5f84abe82a
3
+ metadata.gz: 788c73cc5684ec0d62dbec53486d52626a829f2404055323e5a4d08c3ef4624f
4
+ data.tar.gz: 75d78b6b140a4c36bf5c6e82a685004e8c81f4114b005e3399719d829cdd6f4c
5
5
  SHA512:
6
- metadata.gz: 85b57860c77fc1ee6128e7a2381459ce96d00a42c17586477bdc6f8786b4b1c785578c3da3c9ed55b95db4de779e08dad5d17aad0476260bc2fec27354fd6156
7
- data.tar.gz: bf40604565c9cbf94eb71d4c8516460d645bcdf550fa720231378676ae4e22a5d7557a1f63a2f91f77fd5b280ac9918f652d8931b18ea549f160b8f2179a38e7
6
+ metadata.gz: 7588d0611b7b55dd10f4d971ccd52e10461a4a26f5e260205f67fd23545eaf0c425cd76e967ed545cf5f56d8c97bc932968355623ff659fd0c55baae4921f171
7
+ data.tar.gz: da32a7ef467b2799cb9ed6e49ee3618e6f90634e9d46890001abca16dd1816967a7ec93c0c7e5babc03fc75f3ce68c82582b64645f9b0dd94aa7a776fa498ae6
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VaccinationCharacteristics
4
- VERSION = "1.1.1"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VaccinationCharacteristics
4
+ class VersionWatcher
5
+ attr_reader :current_version_hash
6
+
7
+ def initialize(fetch_latest_version_hash:, polling_interval:, on_update:, on_error: nil)
8
+ raise ArgumentError, "polling_interval must be positive" unless polling_interval.positive?
9
+ raise ArgumentError, "on_update must respond to #call" unless on_update.respond_to?(:call)
10
+
11
+ @fetch_latest_version_hash = fetch_latest_version_hash
12
+ @polling_interval = polling_interval
13
+ @on_update = on_update
14
+ @on_error = on_error
15
+ @current_version_hash = @fetch_latest_version_hash.call
16
+ end
17
+
18
+ def start
19
+ @thread = Thread.new do
20
+ loop do
21
+ sleep(@polling_interval)
22
+ check_for_update
23
+ end
24
+ end
25
+
26
+ self
27
+ end
28
+
29
+ def stop
30
+ @thread&.kill
31
+ @thread&.join
32
+
33
+ self
34
+ end
35
+
36
+ def check_for_update
37
+ latest_version_hash = @fetch_latest_version_hash.call
38
+
39
+ return if latest_version_hash == @current_version_hash
40
+
41
+ @on_update.call(latest_version_hash)
42
+
43
+ @current_version_hash = latest_version_hash
44
+ rescue StandardError => e
45
+ @on_error&.call(e)
46
+ end
47
+
48
+ def running?
49
+ @thread&.alive? || false
50
+ end
51
+ end
52
+ end
@@ -3,6 +3,7 @@
3
3
  require_relative "vaccination_characteristics/version"
4
4
  require_relative "vaccination_characteristics/VaccinationCharacteristicsDatabase_pb"
5
5
  require_relative "vaccination_characteristics/repository"
6
+ require_relative "vaccination_characteristics/version_watcher"
6
7
  require "net/http"
7
8
  require "json"
8
9
  require "ostruct"
@@ -56,6 +57,15 @@ module VaccinationCharacteristics
56
57
  hash
57
58
  end
58
59
 
60
+ def watch_latest_version(cdn_uri: DEFAULT_CDN_URI, polling_interval: 60, on_update:, on_error: nil)
61
+ VersionWatcher.new(
62
+ fetch_latest_version_hash: -> { fetch_latest_version_hash(cdn_uri:) },
63
+ polling_interval:,
64
+ on_update:,
65
+ on_error:
66
+ ).start
67
+ end
68
+
59
69
  def load_from_file(path)
60
70
  Database.new(VaccinationCharacteristicsDatabase.decode(File.read(path)))
61
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vaccination-characteristics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Syadem
@@ -60,6 +60,7 @@ files:
60
60
  - lib/vaccination_characteristics/repositories/condition_repository.rb
61
61
  - lib/vaccination_characteristics/repository.rb
62
62
  - lib/vaccination_characteristics/version.rb
63
+ - lib/vaccination_characteristics/version_watcher.rb
63
64
  homepage: https://docs.nuva.mesvaccins.net
64
65
  licenses:
65
66
  - MIT