Class: DupSendBlocker::SendLog

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/dup_send_blocker/send_log.rb

Defined Under Namespace

Classes: DupLabelError

Class Method Summary collapse

Class Method Details

.write_labels!(labels = []) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/dup_send_blocker/send_log.rb', line 6

def self.write_labels!(labels = [])
  labels = labels.slice(0..2)
  attrs = {}
  [
    :label01, :label02, :label03
  ].each.with_index do |key, i|
    attrs[key] = labels[i].to_s
  end

  instance = nil
  begin
    instance = self.create!(attrs)
  rescue ActiveRecord::RecordNotUnique
    raise DupLabelError.new("#{labels.join(', ')} is duplicated.")
  end

  instance
end