-
Notifications
You must be signed in to change notification settings - Fork 898
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
Adds MiqHelper #15020
Adds MiqHelper #15020
Conversation
lib/miq_helper.rb
Outdated
require 'active_support/core_ext/object/blank' | ||
require 'active_support/string_inquirer' | ||
|
||
module Miq |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we already have a ManageIQ directory and namespace, can we reuse that one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib/manageiq specifically...so I'm expecting this to be in lib/manageiq.rb (File name should match the class path)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I went with lib/miq_helper.rb
because I was matching lib/vmdb_helper.rb
. Fine with changing it if you want. Just wanted to keep it as short as possible as well (otherwise, people will be less inclined to use it 😉 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so lib/manageiq.rb
with a ManageIQ
module is probably the way to go.
This is a commit to help implement the features implemented in the following PRs: ManageIQ#14953 ManageIQ#14967 ManageIQ#15014 ManageIQ#15018 ManageIQ#15019 ManageIQ#15020 Meant to illustrate how they will eventually be used in this PR, and show how they will be implemented when they are merged into master. The prior commits to this one are left in place to show before and after, but this and those will be removed in the final iteration of this pull request, and only the necessary changes needed to implement this in the Rake tasks will be part of this PR. Applying all of the changes for this PR was done as follows: $ git apply <(curl -L ManageIQ#14953) $ git apply <(curl -L ManageIQ#14967) $ git apply <(curl -L ManageIQ#15014) $ git apply <(curl -L ManageIQ#15018) $ git apply <(curl -L ManageIQ#15019) $ git apply <(curl -L ManageIQ#15020) And then with some extra changes on top of that: * Making use of `Miq.env` and `Miq.root` where relevant * Implementing the modulularized PRs in the `tools/utils/mini_*.rb` files where relavant * Various bug fixes (though some seem like they shouldn't be there...) Again, this is meant as a demonstration commit to show the before and after while this is still a POC. Once the necessary pieces are in place on master to make this commit irrelevant, it will be rebased out. It may also change over time as this PR is worked on further.
spec/lib/miq_helper_spec.rb
Outdated
# If tests are not passing, check to see if the spec/spec_helper.rb is being | ||
# loaded properly and initailizing the Vmdb::Application. | ||
|
||
require 'miq_helper' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you name it correctly, this is not needed since the constant lookup on line 11 would autoload it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan, but clearly there is no pleasing you with less typing, so "long name it is"...
spec/lib/miq_helper_spec.rb
Outdated
`#{Gem.ruby} -e 'require "#{miq_lib_file}"; print #{rb_cmd}'` | ||
end | ||
|
||
describe "::env" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: describe ".env" do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😒
spec/lib/miq_helper_spec.rb
Outdated
end | ||
|
||
describe "::env" do | ||
before(:each) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
each is the default so 🔥 ✂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does a reset of the instance variable that is cached on the class (module) level, so reseting to a clean state makes sense for each test (even though it "might" not do anything).
spec/lib/miq_helper_spec.rb
Outdated
end | ||
|
||
describe "::root" do | ||
before(:each) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto on both lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NickLaMuro @Fryguy and I looked at this and other than the nitpicks below, it looks good. The followup PRs will need further review.
Adds two methods to a global ManageIQ module: ManageIQ.env: Functions the same as Rails.env, but falls back to an equivalent implementation when Rails isn't present ManageIQ.root: Functions the same as Rails.root, but falls back to an equivalent implementation when Rails isn't present Tests are done in such a way that if Rails changes it's implementation that causes a difference in what we are seeing here, hopefully these tests will catch it.
Checked commit NickLaMuro@50208b1 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
@Fryguy @jrafanie This and this:
Is actually not even correct. Because we already define the module in If you want to test, just check out this branch (or do the I will let you to battle to determine best course of action after knowing this, since I assume this was a major rational for your decision above (for want to change |
I'm "fine" with avoiding a namespace collision but was under the impression this code would be used outside of the full rails process most times, otherwise there wouldn't be a need to handle when |
@Fryguy are you good with this now? I can see Nick's point about the namespace collision but 🤷 |
This "allows" you to use this outside of a Rails process, but this will replace a lot of code in places where |
[skip ci]
Fix some minor typos from #15020
Adds two methods to a global Miq module:
Miq.env
: Functions the same asRails.env
, but falls back to an equivalent implementation whenRails
isn't presentMiq.root
: Functions the same asRails.root
, but falls back to an equivalent implementation whenRails
isn't presentTests are done in such a way that if
Rails
changes it's implementation that causes a difference in what we are seeing here, hopefully these tests will catch it.Another support PR for #14916
Links