Use keyword args to be more clear:

Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3363#note_12566374
This commit is contained in:
Lin Jen-Shin 2016-06-20 19:11:42 +08:00
parent c491f66952
commit 0671db52a8
3 changed files with 11 additions and 6 deletions

View file

@ -43,17 +43,16 @@ module Gitlab
end.join end.join
end end
def verify_record!(record, exception, name) def verify_record!(record:, invalid_exception:, record_name:)
return if record.persisted? return if record.persisted?
error_title = error_title = "The #{record_name} could not be created for the following reasons:"
"The #{name} could not be created for the following reasons:"
msg = error_title + record.errors.full_messages.map do |error| msg = error_title + record.errors.full_messages.map do |error|
"\n\n- #{error}" "\n\n- #{error}"
end.join end.join
raise exception, msg raise invalid_exception, msg
end end
end end
end end

View file

@ -22,7 +22,10 @@ module Gitlab
validate_permission!(:create_issue) validate_permission!(:create_issue)
verify_record!(create_issue, InvalidIssueError, 'issue') verify_record!(
record: create_issue,
invalid_exception: InvalidIssueError,
record_name: 'issue')
end end
def author def author

View file

@ -19,7 +19,10 @@ module Gitlab
raise NoteableNotFoundError unless sent_notification.noteable raise NoteableNotFoundError unless sent_notification.noteable
raise EmptyEmailError if message.blank? raise EmptyEmailError if message.blank?
verify_record!(create_note, InvalidNoteError, 'comment') verify_record!(
record: create_note,
invalid_exception: InvalidNoteError,
record_name: 'comment')
end end
def author def author