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 :case-insensitive flag to allow case-insensitive matching for :limited_to options 🌈 #644

Merged
merged 2 commits into from
Nov 15, 2019
Merged

Add :case-insensitive flag to allow case-insensitive matching for :limited_to options 🌈 #644

merged 2 commits into from
Nov 15, 2019

Conversation

devanhurst
Copy link
Contributor

Hey all,

After using thor a bit, I thought it'd be useful to be able to match a limited_to option case-insensitively. I often use it for [y/n] prompts, but having the prompt list out all the possibilities [y, Y, n, N, yes, YES, no, NO], for instance, doesn't looks so great. Adding case-insensitive matching allows me to simplify that prompt to [y, yes, n, no].

After reading the contributing guidelines, I see you'd like documentation updated, though documentation doesn't appear to be in the repo, but in a wiki instead. Let me know if there's anything you'd like to see added to this PR to move forward with it.

Thanks!

@devanhurst devanhurst changed the title Add :case-insensitive flag to allow case-insensitive matching for :limited_to options Add :case-insensitive flag to allow case-insensitive matching for :limited_to options 🌈 Feb 11, 2019
@devanhurst devanhurst closed this Jun 29, 2019
@devanhurst devanhurst reopened this Jun 29, 2019
say("Your response must be one of: [#{answers}]. Please try again.") unless correct_answer
end
correct_answer
end

def answer_match(possibilities, answer, case_insensitive)
return possibilities.detect{ |possibility| possibility == answer } unless case_insensitive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we change this to a if/else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right; this isn't really a guard clause. I was all about guard clauses when I wrote this.

flavors = %w(strawberry chocolate vanilla)
expect($stdout).to receive(:print).with("Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n")
expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ', :limited_to => flavors).and_return("moose tracks", "chocolate")
expect(shell.ask('What\'s your favorite Neopolitan flavor?', :limited_to => flavors)).to eq("chocolate")
end

#this one
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#this one

@devanhurst
Copy link
Contributor Author

@rafaelfranca Changes addressed. Saw some seemingly unrelated test failures; they're persistent after rebasing off master. Seen these ones before?

@rafaelfranca
Copy link
Member

Thank you. Yeah. They are from a PR that I just merged. I'll fix them.

@rafaelfranca rafaelfranca merged commit f6e7c91 into rails:master Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants