close_encounters 0.2.1 → 0.2.3

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: e7c56a469fc69cd3a15c93f84ac6a3789415a41d8499df1ea2fd28f5f1aeb07b
4
- data.tar.gz: 8e0b47517ce53491205e3a89c65a56347bed80473e7cb7ac0cec908aaddd06d8
3
+ metadata.gz: 67adeb4fe53671ebcc9e37f040245dd7650ec3afc83433e13415c290617ee356
4
+ data.tar.gz: e7afee308898aa7a25cf3ddfaa652369c74fdb074c014054ee37438babe0b714
5
5
  SHA512:
6
- metadata.gz: a376bbdf0a61509ec060f2624a97498493decb68f7f5655eae922e2980c802378e6c3550fff069dd7d9582cf3c3923befed034bfaa1e735d83375dcbe0156cdb
7
- data.tar.gz: 5af33cc8325f9db5f3a8a5db639049e02509111c83c096f046c1248114e85ede0b743e69fa2f5f4eba57de998c8192ad592c5d91e39c82006c0dbe17e51014d4
6
+ metadata.gz: e0131dcd0a979e6bf3583fe3b90c91b597defbf0f660b8bfaaf2f8d2988a3b1714177148a6cec10078f1a69b8175de7c27d6bccc29523001264ca8c6f667e381
7
+ data.tar.gz: 117c8347983b35986897f55920c4d8472be867598901ca2e83bbf51f2560f083e8c6b9e27559f67c327faa66cbde30b93c1cdb19abd1e9356e792411992ff385
data/CHANGELOG.md CHANGED
@@ -5,24 +5,18 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
6
  and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
- ## [0.2.1] - 2025-03-05
8
+ ## [0.2.3] - 2025-09-08
9
9
 
10
- ### Added
10
+ ### Fixed
11
11
 
12
- - Add alias for verify method as scan.
13
- - Add configuration for auto_contact and verify_scan_statuses.
12
+ - Fix duplicate event creation in `scan` method when status and verification state are unchanged
14
13
 
15
- ### Changed
16
-
17
- - Ensure that events are only created if the status has changed or if the status is in the verify_scan_statuses list and verification fails.
18
-
19
- ## [0.2.0] - 2025-02-26
14
+ ## [0.2.2] - 2025-09-04
20
15
 
21
16
  ### Changed
22
17
 
23
- - Test with Ruby 3.4
18
+ - Update handling of the same status for multiple requests when creating events.
24
19
 
25
- ### Added
20
+ ### Fixed
26
21
 
27
- - Ability to use CloseEncounters::Middleware and CloseEncounters.auto_contact! to automatically track responses from third-party services.
28
- - Add metadata to events for storing extra information about the event.
22
+ - Ensure that status is an integer when creating events and comparing results.
@@ -1,3 +1,3 @@
1
1
  module CloseEncounters
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -31,8 +31,13 @@ module CloseEncounters
31
31
  # @param response [String] the response object
32
32
  def contact(name, status:, response:)
33
33
  service = ParticipantService.find_by!(name:)
34
- unless service.events.newest.pick(:status) == status
35
- service.events.create!(status: status, response:)
34
+ status = status.to_i # Ensure status is always an integer
35
+
36
+ # Use a transaction with a lock to prevent race conditions
37
+ service.with_lock do
38
+ unless service.events.newest.pick(:status) == status
39
+ service.events.create!(status: status, response:)
40
+ end
36
41
  end
37
42
  end
38
43
 
@@ -49,14 +54,26 @@ module CloseEncounters
49
54
  # @param verifier [Proc] the verification callable which must also respond to to_s
50
55
  def scan(name, status:, response:, verifier:)
51
56
  service = ParticipantService.find_by!(name:)
52
- last_status = service.events.newest.pick(:status)
57
+ status = status.to_i # Ensure status is always an integer
53
58
 
54
- if last_status != status
55
- verified = verifier.call(response)
56
- service.events.create!(status:, response:, metadata: {verified:, verification: verifier.to_s})
57
- elsif verify_scan_statuses.include?(status)
59
+ service.with_lock do
60
+ last_event = service.events.newest.first
61
+ last_status = last_event&.status
62
+ last_verified = last_event&.verified?
63
+
64
+ # Calculate current verification result
58
65
  verified = verifier.call(response)
59
- service.events.create!(status:, response:, metadata: {verified:, verification: verifier.to_s}) if !verified
66
+
67
+ # Create a new event if:
68
+ # 1. Status has changed OR
69
+ # 2. Status is in verify_scan_statuses AND verified flag has changed
70
+ if last_status != status
71
+ # Status changed, always create new event
72
+ service.events.create!(status:, response:, metadata: {verified:, verification: verifier.to_s})
73
+ elsif verify_scan_statuses.include?(status) && last_verified != verified
74
+ # Status same but verification result changed for a monitored status
75
+ service.events.create!(status:, response:, metadata: {verified:, verification: verifier.to_s})
76
+ end
60
77
  end
61
78
  end
62
79
  alias_method :verify, :scan
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: close_encounters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Gay
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-03-05 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: railties
@@ -129,7 +128,6 @@ metadata:
129
128
  homepage_uri: https://github.com/SOFware/close_encounters
130
129
  source_code_uri: https://github.com/SOFware/close_encounters
131
130
  changelog_uri: https://github.com/SOFware/close_encounters/blob/main/CHANGELOG.md
132
- post_install_message:
133
131
  rdoc_options: []
134
132
  require_paths:
135
133
  - lib
@@ -144,8 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
142
  - !ruby/object:Gem::Version
145
143
  version: '0'
146
144
  requirements: []
147
- rubygems_version: 3.5.9
148
- signing_key:
145
+ rubygems_version: 3.6.7
149
146
  specification_version: 4
150
147
  summary: Close Encounters of the Third Party
151
148
  test_files: []