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

Adds MiqHelper #15020

Merged
merged 1 commit into from
Jun 5, 2017
Merged

Adds MiqHelper #15020

merged 1 commit into from
Jun 5, 2017

Conversation

NickLaMuro
Copy link
Member

Adds two methods to a global Miq module:

  • Miq.env: Functions the same as Rails.env, but falls back to an equivalent implementation when Rails isn't present
  • Miq.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.

Another support PR for #14916

Links

require 'active_support/core_ext/object/blank'
require 'active_support/string_inquirer'

module Miq
Copy link
Member

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?

Copy link
Member

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)

Copy link
Member Author

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 😉 )

Copy link
Member

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.

NickLaMuro added a commit to NickLaMuro/manageiq that referenced this pull request May 9, 2017
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.
NickLaMuro added a commit to NickLaMuro/manageiq that referenced this pull request May 12, 2017
@NickLaMuro NickLaMuro mentioned this pull request May 20, 2017
10 tasks
NickLaMuro added a commit to NickLaMuro/manageiq that referenced this pull request May 23, 2017
# 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'
Copy link
Member

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.

Copy link
Member Author

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"...

`#{Gem.ruby} -e 'require "#{miq_lib_file}"; print #{rb_cmd}'`
end

describe "::env" do
Copy link
Member

Choose a reason for hiding this comment

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

nit: describe ".env" do

Copy link
Member Author

Choose a reason for hiding this comment

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

😒

end

describe "::env" do
before(:each) do
Copy link
Member

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 🔥 ✂️

Copy link
Member Author

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).

end

describe "::root" do
before(:each) do
Copy link
Member

Choose a reason for hiding this comment

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

ditto on both lines

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@jrafanie jrafanie left a 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.
@miq-bot
Copy link
Member

miq-bot commented Jun 1, 2017

Checked commit NickLaMuro@50208b1 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks fine. 🍰

@NickLaMuro
Copy link
Member Author

@Fryguy @jrafanie This and this:

Ok, so lib/manageiq.rb with a ManageIQ module is probably the way to go.

If you name it correctly, this is not needed since the constant lookup on line 11 would autoload it.

Is actually not even correct. Because we already define the module in app/models/manageiq/..., and those tend to get loaded very early in most of the application processes. In this case, it means "Rails" already knows about the module, and so it just tries calling the method on that module (which has nothing on it defined).

If you want to test, just check out this branch (or do the git apply method in the PR description), and run rspec spec/lib/manageiq_spec.rb to see what happens after you remove the require.

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 Miq to ManageIQ that is).

@jrafanie
Copy link
Member

jrafanie commented Jun 2, 2017

Is actually not even correct. Because we already define the module in app/models/manageiq/..., and those tend to get loaded very early in most of the application processes. In this case, it means "Rails" already knows about the module, and so it just tries calling the method on that module (which has nothing on it defined).

If you want to test, just check out this branch (or do the git apply method in the PR description), and run rspec spec/lib/manageiq_spec.rb to see what happens after you remove the require.

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 Miq to ManageIQ that is).

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 Rails isn't defined. I don't see this being used that frequently to worry about having to spell out ManageIQ. Maybe I'm wrong?

@jrafanie
Copy link
Member

jrafanie commented Jun 2, 2017

@Fryguy are you good with this now? I can see Nick's point about the namespace collision but 🤷

@NickLaMuro
Copy link
Member Author

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 Rails isn't defined.

This "allows" you to use this outside of a Rails process, but this will replace a lot of code in places where Rails.root would normally be used, and shared between processes that use Rails and those that down (MiqServer being an example class for that).

@jrafanie jrafanie merged commit 037d27e into ManageIQ:master Jun 5, 2017
@jrafanie jrafanie added this to the Sprint 62 Ending Jun 5, 2017 milestone Jun 5, 2017
jrafanie added a commit to jrafanie/manageiq that referenced this pull request Jun 5, 2017
bdunne added a commit that referenced this pull request Jun 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants