Class: CycloneLariat::Repo::Sequel::InboxMessages
- Inherits:
-
Object
- Object
- CycloneLariat::Repo::Sequel::InboxMessages
- Defined in:
- lib/cyclone_lariat/repo/sequel/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/sequel/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/sequel/inbox_messages.rb', line 12 def dataset @dataset end |
Instance Method Details
#create(msg) ⇒ Object
26 27 28 |
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 26 def create(msg) dataset.insert Mappers::InboxMessages.to_row(msg) end |
#disabled? ⇒ Boolean
22 23 24 |
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 22 def disabled? dataset.nil? end |
#each_unprocessed ⇒ Object
48 49 50 51 52 53 |
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 48 def each_unprocessed dataset.where(processed_at: nil).each do |row| msg = build Mappers::InboxMessages.from_row(row) yield(msg) end end |
#each_with_client_errors ⇒ Object
55 56 57 58 59 60 |
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 55 def each_with_client_errors dataset.where { (processed_at !~ nil) & ( !~ nil) }.each do |row| msg = build Mappers::InboxMessages.from_row(row) yield(msg) end end |
#enabled? ⇒ Boolean
18 19 20 |
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 18 def enabled? !dataset.nil? end |
#exists?(uuid:) ⇒ Boolean
30 31 32 |
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 30 def exists?(uuid:) dataset.where(uuid: uuid).limit(1).any? end |
#find(uuid:) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 41 def find(uuid:) row = dataset.where(uuid: uuid).first return if row.nil? build Mappers::InboxMessages.from_row(row) end |
#processed!(uuid:, error: nil) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 34 def processed!(uuid:, error: nil) data = { processed_at: ::Sequel.function(:NOW) } data.merge!(client_error_message: error., client_error_details: JSON.generate(error.details)) if error !dataset.where(uuid: uuid).update(data).zero? end |