Permalink
Browse files

Restore extracted methods

* Show large class after extract method
  • Loading branch information...
jferris committed Feb 14, 2013
1 parent bd74a9f commit 65f1b4287f8d79f3b30825a9ea966aa0ccc81930
Showing with 34 additions and 15 deletions.
  1. +34 −15 example_app/app/controllers/invitations_controller.rb
@@ -7,32 +7,51 @@ def new

def create
@survey = Survey.find(params[:survey_id])

@recipients = params[:invitation][:recipients]
recipient_list = @recipients.gsub(/\s+/, '').split(/[\n,;]+/)

@invalid_recipients = recipient_list.map do |item|
unless item.match(EMAIL_REGEX)
item
end
end.compact

@message = params[:invitation][:message]

if @invalid_recipients.empty? && @message.present?
if valid_recipients? && valid_message?
recipient_list.each do |email|
invitation = Invitation.create(
survey: @survey,
sender: current_user,
recipient_email: email,
status: 'pending'
)
Mailer.invitation_notification(invitation, @message)
Mailer.invitation_notification(invitation, message)
end

redirect_to survey_path(@survey), notice: 'Invitation successfully sent'
else
@recipients = recipients
@message = message
render 'new'
end
end

private

def valid_recipients?
invalid_recipients.empty?
end

def valid_message?
message.present?
end

def invalid_recipients
@invalid_recipients ||= recipient_list.map do |item|
unless item.match(EMAIL_REGEX)
item
end
end.compact
end

def recipient_list
@recipient_list ||= recipients.gsub(/\s+/, '').split(/[\n,;]+/)
end

def recipients
params[:invitation][:recipients]
end

def message
params[:invitation][:message]
end
end

0 comments on commit 65f1b42

Please sign in to comment.