Skip to content
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

Merged
merged 1 commit into from
May 24, 2017

Conversation

el-mapache
Copy link
Contributor

Why: To better adhere to our conventions of returning an error
object from from objects

end

def personal_key_format_matches?
personal_key =~ /\A#{PersonalKeyFormatter.new.regexp}\Z/
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@el-mapache el-mapache force-pushed the ab-add-errors-to-pkey-form branch 3 times, most recently from 7e4c19a to e846836 Compare May 24, 2017 14:38
Copy link
Contributor

@zachmargolis zachmargolis left a 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
Copy link
Contributor

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

Copy link
Contributor Author

@el-mapache el-mapache May 24, 2017

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 😄

**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
@el-mapache el-mapache merged commit d596a41 into master May 24, 2017
@el-mapache el-mapache deleted the ab-add-errors-to-pkey-form branch May 24, 2017 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants