Class: Labimotion::DoseRespRequest
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Labimotion::DoseRespRequest
- Defined in:
- lib/labimotion/models/dose_resp_request.rb
Constant Summary collapse
- STATE_ERROR =
State constants
-1
- STATE_INITIAL =
0- STATE_PROCESSING =
1- STATE_COMPLETED =
2
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#expired? ⇒ Boolean
Instance methods.
- #mark_completed! ⇒ Object
- #mark_error!(message = nil) ⇒ Object
- #mark_processing! ⇒ Object
- #revoke! ⇒ Object
- #revoked? ⇒ Boolean
- #track_access! ⇒ Object
Instance Method Details
#active? ⇒ Boolean
47 48 49 |
# File 'lib/labimotion/models/dose_resp_request.rb', line 47 def active? !expired? && !revoked? end |
#expired? ⇒ Boolean
Instance methods
39 40 41 |
# File 'lib/labimotion/models/dose_resp_request.rb', line 39 def expired? expires_at.present? && expires_at < Time.current end |
#mark_completed! ⇒ Object
59 60 61 |
# File 'lib/labimotion/models/dose_resp_request.rb', line 59 def mark_completed! update!(state: STATE_COMPLETED) end |
#mark_error!(message = nil) ⇒ Object
63 64 65 |
# File 'lib/labimotion/models/dose_resp_request.rb', line 63 def mark_error!( = nil) update!(state: STATE_ERROR, resp_message: ) end |
#mark_processing! ⇒ Object
55 56 57 |
# File 'lib/labimotion/models/dose_resp_request.rb', line 55 def mark_processing! update!(state: STATE_PROCESSING) if state == STATE_INITIAL end |
#revoke! ⇒ Object
51 52 53 |
# File 'lib/labimotion/models/dose_resp_request.rb', line 51 def revoke! update!(revoked_at: Time.current, state: STATE_ERROR) end |
#revoked? ⇒ Boolean
43 44 45 |
# File 'lib/labimotion/models/dose_resp_request.rb', line 43 def revoked? revoked_at.present? end |
#track_access! ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/labimotion/models/dose_resp_request.rb', line 67 def track_access! increment!(:access_count) update_columns( first_accessed_at: first_accessed_at || Time.current, last_accessed_at: Time.current ) end |