app/models/concerns/po_box/emailable.rb in po_box-0.1.1 vs app/models/concerns/po_box/emailable.rb in po_box-0.1.2
- old
+ new
@@ -3,17 +3,17 @@
extend ActiveSupport::Concern
included do
has_many :inboxes, as: :emailable, class_name: "PoBox::Inbox", dependent: :destroy
- after_create_commit :set_inbox
+ after_create_commit :generate_inbox
accepts_nested_attributes_for :inboxes, allow_destroy: true
private
- def set_inbox
+ def generate_inbox
return if inboxes.any?
inbox_address = if email.present?
"#{email.split("@").first}##{SecureRandom.hex(2)}"
else
@@ -21,10 +21,10 @@
end
inbox = inboxes.new
loop do
inbox.address = inbox_address
- break unless PoBox.emailable_class.joins(:inboxes).where(po_box_inboxes: {address: inbox.address}).exists?
+ break unless PoBox::Inbox.find_by(address: inbox.address).present?
end
save
end
end