Skip to content

Commit 6de6918

Browse files
author
David Zuckerman
committed
Changing doemoff_patron_email_form to use struct similar to affiliate_borrower
1 parent d301426 commit 6de6918

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

app/mailers/request_mailer.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ def doemoff_room_failure_email(empid, displayname, note)
4040
mail(to: admin_to)
4141
end
4242

43-
# Sends doemoff patron email
44-
def doemoff_patron_email(email_form)
45-
@email_form = email_form
46-
mail(to: @email_form.patron_email, bcc: @email_form.recipient_email, reply_to: @email_form.recipient_email,
47-
subject: 'Message from Doe/Moffitt Libraries Staff')
43+
def doemoff_patron_email(payload)
44+
@email_form = DoemoffPatronEmailForm::PatronEmail.new(**payload)
45+
46+
mail(
47+
to: @email_form.patron_email,
48+
bcc: @email_form.recipient_email,
49+
reply_to: @email_form.recipient_email,
50+
subject: 'Message from Doe/Moffitt Libraries Staff'
51+
)
4852
end
4953

5054
# Sends the Security Incident form email
Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
class DoemoffPatronEmailForm < Form
2-
attr_accessor(
3-
:patron_email,
4-
:patron_message,
5-
:sender,
6-
:recipient_email
7-
)
2+
ATTRIBUTES = %i[
3+
patron_email
4+
patron_message
5+
sender
6+
recipient_email
7+
].freeze
8+
9+
PatronEmail = Struct.new(*ATTRIBUTES, keyword_init: true)
10+
11+
attr_accessor(*ATTRIBUTES)
812

913
validates :patron_email,
1014
email: true,
1115
presence: true
1216

1317
validates :patron_message, :sender, :recipient_email, presence: true
1418

15-
private
19+
def to_h
20+
ATTRIBUTES.index_with { |attr| public_send(attr) }
21+
end
22+
23+
def submit!
24+
raise ActiveModel::ValidationError, self unless valid?
1625

17-
def submit
18-
RequestMailer.doemoff_patron_email(:patron_email, :patron_message, :sender, :recipient_email).deliver_later
26+
RequestMailer.doemoff_patron_email(to_h).deliver_later
1927
end
2028
end

0 commit comments

Comments
 (0)