Class: CycloneLariat::Repo::ActiveRecord::InboxMessages

Inherits:
Object
  • Object
show all
Defined in:
lib/cyclone_lariat/repo/active_record/inbox_messages.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#datasetObject (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

Returns:

  • (Boolean)


22
23
24
# File 'lib/cyclone_lariat/repo/active_record/inbox_messages.rb', line 22

def disabled?
  dataset.nil?
end

#each_unprocessedObject



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 = build_message_from_ar_row(row)
    yield(msg)
  end
end

#each_with_client_errorsObject



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 = build_message_from_ar_row(row)
      yield(msg)
    end
end

#enabled?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/cyclone_lariat/repo/active_record/inbox_messages.rb', line 18

def enabled?
  !dataset.nil?
end

#exists?(uuid:) ⇒ Boolean

Returns:

  • (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?

  build_message_from_ar_row(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: current_timestamp_from_db }
  data.merge!(client_error_message: error.message, client_error_details: JSON.generate(error.details)) if error

  message = dataset.where(uuid: uuid).first
  return false unless message

  message.update(data)
end