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

Force Gem Best Practice #229

Merged
merged 1 commit into from Apr 4, 2018
Merged

Force Gem Best Practice #229

merged 1 commit into from Apr 4, 2018

Conversation

plribeiro3000
Copy link
Member

All classes defined from within a Gem should be inside its own namespace
to avoid conflicts with other gems

cc/ @geemus @icco @Temikus @lanej @fog/core

This will be the first PR of many to

  • Achieve minimum consistency across all providers
  • Implement some best practices
  • Improve loading of the libraries by using bundle instead of manually requiring it

@@ -21,11 +21,20 @@ def service(new_service, constant_string)
Fog.services[new_service] ||= []
Fog.services[new_service] |= [to_s.split("::").last.downcase.to_sym]
@services_registry ||= {}
@services_registry[new_service] = [to_s, constant_string].join("::")
@services_registry[new_service] = service_klass(constant_string)
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure how this is working now. As of my understanding it will always load services in the form of Fog::<PROVIDER>::<Service> and we have many providers doing Fog::<Service>::<PROVIDER>

Copy link
Member

Choose a reason for hiding this comment

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

If I recall correctly, it was all Fog::<PROVIDER>::<SERVICE> initially, and we might have changed some along the way in the hopes that the other way was better? It would be best, I suspect, to pick one and stick to it though (which would probably be the old way). What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree to sticking to one. So my idea is to deprecate the one that might give us problems (2 different providers define a class named Fog::Compute::Utils) and drop support in a major version. This is being done from the service_klass method.

@coveralls
Copy link

coveralls commented Apr 2, 2018

Coverage Status

Coverage increased (+0.04%) to 76.197% when pulling 473abf8 on best-practices into 8d34a75 on master.

def require_service_provider_library(service, provider)
require "fog/#{provider}/#{service}"
rescue LoadError # Try to require the service provider in an alternate location
Fog::Logger.deprecation('Prefer to define all Services within the Provider Namespace instead!')
Copy link
Member

Choose a reason for hiding this comment

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

I think maybe a more specific error would be helpful here. Like Unable to load "#{fog/#{provider}/#{service}". What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm. Good idea. How to announce the deprecation as well?

Fog.const_get(provider_name).const_get(*const_get_args(service_name))
rescue NameError # Try to find the constant from in an alternate location
Fog::Logger.deprecation('Prefer to define all Services within the Provider Namespace instead!')
Copy link
Member

Choose a reason for hiding this comment

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

Similarly, a more specific error here would probably be less confusing, though I'm much less sure how to word it helpfully here. What do you think?

@@ -10,6 +10,7 @@
require "minitest/autorun"
require "minitest/spec"
require "minitest/stub_const"
require "pry"
Copy link
Member

Choose a reason for hiding this comment

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

I suspect it may have been unintentional to commit this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ops. Good catch. =)

Copy link
Member

@geemus geemus left a comment

Choose a reason for hiding this comment

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

Overall it looks good. I think standardizing toward the usage you selected sounds great. The main feedback would just be to try and provide more end-user understandable error messages in a couple places and then I think we should be good to go. Thanks!

@plribeiro3000
Copy link
Member Author

plribeiro3000 commented Apr 3, 2018

Will work on your comments later today. Thanks for the review!

All classes defined from within a Gem should be inside its own namespace
to avoid conflicts with other gems
@plribeiro3000
Copy link
Member Author

Here we go @geemus. I ended up doing 2 messages, one to tell it could not load the class and another one to notify about the deprecation.

What do you think about this approach? Maybe too verbose?

@geemus
Copy link
Member

geemus commented Apr 4, 2018

Looks good, thanks!

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

3 participants