-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add errors to FormResponse in PersonalKeyForm #1450
Conversation
59a82bb
to
ba8419e
Compare
end | ||
|
||
def personal_key_format_matches? | ||
personal_key =~ /\A#{PersonalKeyFormatter.new.regexp}\Z/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the PersonalKeyFormatter#regexp
should return a regex object. I'm assuming it returns a plain string for something in a view or with JS, should we break out two methods? regexp_str
and regexp
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually not sure, I just moved the declaration into a method to satisfy line length requirements! I was also confused why it didn't return a regex, I can look into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zachmargolis I update the PeronalKeyFormatter
class. I split up the method and moved the variables into constants, since we shouldn't have to recompute the regex string.
7e4c19a
to
e846836
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! One last nit, thanks for cleaning this up, feel free to fix it if you want, otherwise just got ahead & merge
VALID_CHAR = '[a-zA-Z0-9]'.freeze | ||
VALID_WORD = "#{VALID_CHAR}{#{CHAR_COUNT}}" | ||
REGEXP = "(?:#{VALID_WORD}([\s-])?){#{WORD_COUNT - 1}}#{VALID_WORD}".freeze | ||
|
||
def regexp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny nit .... there's no point in instantating this object, let's make these class methods?
def self.regexp
when when we use it we don't need the .new
PersonalKeyFormatter.regexp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah totally fine with that, I wasn't sure why it was being called with .new
in the first place, so I left it alone 😄
e202583
to
beaaee6
Compare
**Why**: To better adhere to our conventions of returning an error object from from objects Return regex object from PersonalKeyFormatter **Why**: The method .regexp on PersonalKeyFormatter seems like it should return an actual regex and not a string **How**: Make two methods, one for use by ruby, returning the object, and one for use on the client, returning a string. Use class methods instead of new **Why**: This is simpler, instantiation wasn't really needed
Why: To better adhere to our conventions of returning an error
object from from objects