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

Change inflector to one that doesn't monkey patch #121

Closed
cllns opened this issue May 24, 2018 · 5 comments
Closed

Change inflector to one that doesn't monkey patch #121

cllns opened this issue May 24, 2018 · 5 comments

Comments

@cllns
Copy link

cllns commented May 24, 2018

I'd like to add Skylight to my Hanami project, but it depends on ActiveSupport. I see that someone else suggested removing this dependency but the proposal wasn't accepted.

In general, I'm really hesitant to pull ActiveSupport into my project, since it's very easy to accidentally introduce monkey-patched method calls. I really like Skylight so this is a huge bummer for me, but the risk of accidentally adding a monkey patch is too high for me.

@wagenet said:

it isn't our intent to use the extensions. If you notice that we're causing them to be used anywhere, please let me know.

I'm not sure where it's happening, but there's a core extension (monkey patch) being used, via ActiveSupport's Inflector.

Without skylight in my Gemfile, "dog".pluralize rightly raises a NoMethodError.
With skylight in my Gemfile, "dog".pluralize returns "dogs".

A good, simple, and maintained, non-core extension library for inflections is dry-inflector.

@zvkemp
Copy link
Contributor

zvkemp commented May 24, 2018

Thanks for the report, @cllns . Unfortunately I wasn't able to reproduce the effect you described in a new Hanami project (adding skylight did not cause string extensions to load). Could you please provide more information about what versions of Hanami and Skylight you are using, or a reproducible scenario that we could investigate?

@cllns
Copy link
Author

cllns commented May 25, 2018

@zvkemp Thanks for the quick response.

What a doozy! Took me a couple hours but I realized it was actually a bug with how a dependency of a dependency of hanami-model handles inflections: by automatically trying to require ActiveSupport::Inflector as a back-end for the table name inflections. The reason it doesn't show up in a new app is that there are no models or other DB code, so that code never gets executed. (See the reference issue above for details, if you're interested)

Closing this since it's not a bug with skylight-ruby. I'm still super skeptical of adding activesupport as a transitive dependency though. (Now more than ever, even!)

@cllns cllns closed this as completed May 25, 2018
@wagenet
Copy link
Contributor

wagenet commented Jun 12, 2018

@cllns My understanding is that requiring ActiveSupport shouldn't automatically do any monkey-patching. You have to explicitly require certain files for that to happen. Am I mistaken?

@cllns
Copy link
Author

cllns commented Jun 12, 2018

@wagenet Yup! The issue is that a transitive dependency was requiring ActiveSupport::Inflector because it was available.

@wagenet
Copy link
Contributor

wagenet commented Jun 12, 2018

@cllns got it. Thanks for clarifying.

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