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

Fix Railtie / Rails initializers #24

Merged
merged 7 commits into from
Sep 27, 2018
Merged

Fix Railtie / Rails initializers #24

merged 7 commits into from
Sep 27, 2018

Conversation

haffla
Copy link
Contributor

@haffla haffla commented Sep 27, 2018

Hello! First of all thanks for this gem.
I've noticed a problem with the Railtie initializers.

WebValve.enabled? is called inside the Railtie class. The problem with this is that user defined environment variables such as WEBVALVE_ENABLED might not be set when this class is loaded. This is true for users of Figaro or users who dynamically set env vars in an initializer or config file. So the call to enabled? should be inside the initializers.

Moreover Rails.logger (which might be used in enabled? is not initialized at this point. It is actually not initialized when webvalve.set_autoload_paths runs. To solve this I added the safe navigation operator in enabled?.

@nanda-prbot
Copy link

@haffla needs to request domain and platform reviewers.

Copy link
Member

@samandmoore samandmoore left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this PR. I left a few thoughts.

lib/webvalve.rb Outdated Show resolved Hide resolved
lib/webvalve/railtie.rb Outdated Show resolved Hide resolved
@haffla
Copy link
Contributor Author

haffla commented Sep 27, 2018

Can I ask why logger= is delegated to Rails? I don't see it used anywhere? Also wouldn't this change the Rails logger when doing WebValve.logger = some_logger? Is this intended behaviour?

@haffla
Copy link
Contributor Author

haffla commented Sep 27, 2018

Don't merge yet, I found a small problem with this!

@smudge
Copy link
Member

smudge commented Sep 27, 2018

Delegating logger= to Rails is probably not intended (since it would lead to pretty surprising behavior) and is probably safe to remove. (@samandmoore?)

(Edit: or, rather than removing, we could define it directly and allow it to set a new logger for just Webvalve)

@samandmoore
Copy link
Member

Delegating logger= to Rails is probably not intended (since it would lead to pretty surprising behavior) and is probably safe to remove. (@samandmoore?)

yea, i don't think i thought that one through enough. the fancy logger stuff that's going on here is meant to allow for use of Rails.logger when this library is used with Rails and a default logger or custom logger when used with any other framework.

lib/webvalve.rb Outdated Show resolved Hide resolved
lib/webvalve.rb Outdated Show resolved Hide resolved
@haffla
Copy link
Contributor Author

haffla commented Sep 27, 2018

This part of the code is not covered by the specs and I don't know yet how to test this using a real Rails application. The dummy project in spec/dummy is not in use is it?

@haffla
Copy link
Contributor Author

haffla commented Sep 27, 2018

Should logger= be made available for both Rails and non Rails projects. Then we could remove the delegation of logger= to Rails.

@samandmoore
Copy link
Member

This part of the code is not covered by the specs and I don't know yet how to test this using a real Rails application. The dummy project in spec/dummy is not in use is it?

i believe the spec/dummy app should be used by the test suite. but yea, we don't have any real integration tests right now.

there's an example sinatra app in the examples directory that can be used to verify that we didn't break anything there.

Should logger= be made available for both Rails and non Rails projects. Then we could remove the delegation of logger= to Rails.

yea. let's do that.

@haffla
Copy link
Contributor Author

haffla commented Sep 27, 2018

@samandmoore is this OK now?

@samandmoore
Copy link
Member

looks good. thank you for the submission.

/domain @samandmoore
/platform @samandmoore
<<domainlgtm platformlgtm

@nanda-prbot
Copy link

Approved! 🙌 👻 💫

@samandmoore samandmoore merged commit 208fcd3 into Betterment:master Sep 27, 2018
@samandmoore
Copy link
Member

@haffla i will look into releasing a new version tomorrow. thanks again.

@samandmoore
Copy link
Member

@haffla took a bit longer than expected, but v0.9.7 is released! thanks again.

@haffla
Copy link
Contributor Author

haffla commented Oct 1, 2018

Thanks a lot for your support!

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.

None yet

4 participants