Module: CloseEncounters
- Defined in:
- lib/close_encounters.rb,
lib/close_encounters/engine.rb,
lib/close_encounters/version.rb,
app/models/close_encounters/participant_event.rb,
app/models/close_encounters/application_record.rb,
app/models/close_encounters/participant_service.rb
Defined Under Namespace
Classes: ApplicationRecord, Engine, ParticipantEvent, ParticipantService
Constant Summary collapse
- VERSION =
"0.1.3"
Class Method Summary collapse
-
.contact(name, status:, response:) ⇒ Object
Record a contact with a third party service if the status has changed.
-
.ensure_service(name, connection_info: {}) ⇒ Object
Ensure that a participant service exists.
-
.status(name) ⇒ Integer
Get the status of the most recent contact with a third party service.
Class Method Details
.contact(name, status:, response:) ⇒ Object
Record a contact with a third party service if the status has changed
15 16 17 18 19 20 |
# File 'lib/close_encounters.rb', line 15 def contact(name, status:, response:) service = ParticipantService.find_by!(name:) unless service.events.newest.pick(:status) == status service.events.create!(status: status, response:) end end |
.ensure_service(name, connection_info: {}) ⇒ Object
Ensure that a participant service exists
34 35 36 37 38 |
# File 'lib/close_encounters.rb', line 34 def ensure_service(name, connection_info: {}) ParticipantService.find_or_create_by!(name: name) do |service| service.connection_info = connection_info unless service.connection_info.present? end end |
.status(name) ⇒ Integer
Get the status of the most recent contact with a third party service
26 27 28 |
# File 'lib/close_encounters.rb', line 26 def status(name) ParticipantService.find_by!(name: name).events.newest.pick(:status) end |