Class: CycloneLariat::Repo::ActiveRecord::InboxMessages
- Inherits:
-
Object
- Object
- CycloneLariat::Repo::ActiveRecord::InboxMessages
- Defined in:
- lib/cyclone_lariat/repo/active_record/inbox_messages.rb
Instance Attribute Summary collapse
-
#dataset ⇒ Object
readonly
Returns the value of attribute dataset.
Instance Method Summary collapse
- #create(msg) ⇒ Object
- #disabled? ⇒ Boolean
- #each_unprocessed ⇒ Object
- #each_with_client_errors ⇒ Object
- #enabled? ⇒ Boolean
- #exists?(uuid:) ⇒ Boolean
- #find(uuid:) ⇒ Object
-
#initialize(dataset) ⇒ InboxMessages
constructor
A new instance of InboxMessages.
- #processed!(uuid:, error: nil) ⇒ Object
Constructor Details
#initialize(dataset) ⇒ InboxMessages
Returns a new instance of InboxMessages.
14 15 16 |
# File 'lib/cyclone_lariat/repo/active_record/inbox_messages.rb', line 14 def initialize(dataset) @dataset = dataset end |
Instance Attribute Details
#dataset ⇒ Object (readonly)
Returns the value of attribute dataset.
12 13 14 |
# File 'lib/cyclone_lariat/repo/active_record/inbox_messages.rb', line 12 def dataset @dataset end |
Instance Method Details
#create(msg) ⇒ Object
26 27 28 |
# File 'lib/cyclone_lariat/repo/active_record/inbox_messages.rb', line 26 def create(msg) dataset.create(Mappers::InboxMessages.to_row(msg)).uuid end |
#disabled? ⇒ Boolean
22 23 24 |
# File 'lib/cyclone_lariat/repo/active_record/inbox_messages.rb', line 22 def disabled? dataset.nil? end |
#each_unprocessed ⇒ Object
51 52 53 54 55 56 |
# File 'lib/cyclone_lariat/repo/active_record/inbox_messages.rb', line 51 def each_unprocessed dataset.where(processed_at: nil).each do |row| msg = (row) yield(msg) end end |
#each_with_client_errors ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/cyclone_lariat/repo/active_record/inbox_messages.rb', line 58 def each_with_client_errors dataset .where.not(processed_at: nil) .where.not(client_error_message: nil) .each do |row| msg = (row) yield(msg) end end |
#enabled? ⇒ Boolean
18 19 20 |
# File 'lib/cyclone_lariat/repo/active_record/inbox_messages.rb', line 18 def enabled? !dataset.nil? end |
#exists?(uuid:) ⇒ Boolean
30 31 32 |
# File 'lib/cyclone_lariat/repo/active_record/inbox_messages.rb', line 30 def exists?(uuid:) dataset.exists?(uuid: uuid) end |
#find(uuid:) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/cyclone_lariat/repo/active_record/inbox_messages.rb', line 44 def find(uuid:) row = dataset.where(uuid: uuid).first return if row.nil? (row) end |
#processed!(uuid:, error: nil) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/cyclone_lariat/repo/active_record/inbox_messages.rb', line 34 def processed!(uuid:, error: nil) data = { processed_at: } data.merge!(client_error_message: error., client_error_details: JSON.generate(error.details)) if error = dataset.where(uuid: uuid).first return false unless .update(data) end |