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

reusable params with shared helper - Boolean type problem #1115

Closed
chrisyoumans opened this issue Aug 21, 2015 · 3 comments
Closed

reusable params with shared helper - Boolean type problem #1115

chrisyoumans opened this issue Aug 21, 2015 · 3 comments

Comments

@chrisyoumans
Copy link

When defining a reusable parameter using a shared helper, if my parameter is of type Boolean, I receive a NameError. (block in module:ParamsHelper': uninitialized constant ParamsHelper::Boolean (NameError))

module ParamsHelper
  extend Grape::API::Helpers

  params :forensics do
    optional :forensics, type: Boolean, default: false, desc: "Turn forensics node on or off."
  end
end

All other types seem to work fine. It's as if it doesn't know where to look for the Boolean type. I even tried type: Grape::Validations::ParamsScope::Boolean and received: "block in module:ParamsHelper': uninitialized constant Grape::Validations::ParamsScope::Boolean (NameError)." I did the equivalent with String and while it threw a warning, it worked.

It's very possible I'm missing something, but considering the other types seem to work fine, I'm not sure what it could be.

@chrisyoumans
Copy link
Author

OK, the problem goes away if I use type: Virtus::Attribute::Boolean. Seems a little strange considering that isn't necessary when the params are declared inside of the resource, but it works.

@rnubel
Copy link
Contributor

rnubel commented Aug 21, 2015

This behavior is because that 'Boolean' constant is defined under Grape::API, here. So it can be reached when you're inside an instance of Grape::API, but not from your module. I agree it's a little silly, though; it's always seemed weird to me that Ruby doesn't have a Boolean type when it has Integer, String, etc.

@dblock
Copy link
Member

dblock commented Aug 22, 2015

I am not sure we can do anything about this, closing.

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

No branches or pull requests

3 participants