Skip to content

Explain deprecation of service/provider format #241

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

Merged
merged 1 commit into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/fog/core/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,22 @@ def services
@services_registry.keys
end

# Returns service constant path, with provider, as string. If
# "provider::service" is defined (the preferred format) then it returns that
# string, otherwise it returns the deprecated string "service::provider".
def service_klass(constant_string)
eval([to_s, constant_string].join("::"))
[to_s, constant_string].join("::")
rescue NameError
provider = to_s.split("::").last
Fog::Logger.deprecation("Unable to load #{[to_s, constant_string].join("::")}")
Fog::Logger.deprecation("The format #{['Fog', constant_string, provider].join("::")} is deprecated")
Fog::Logger.deprecation(
format(
Fog::ServicesMixin::E_SERVICE_PROVIDER_CONSTANT,
service: constant_string,
provider: provider
)
)
['Fog', constant_string, provider].join("::")
end
end
Expand Down
21 changes: 19 additions & 2 deletions lib/fog/core/services_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
module Fog
module ServicesMixin
E_SERVICE_PROVIDER_CONSTANT = <<-EOS.gsub(/\s+/, ' ').strip.freeze
Falling back to deprecated constant Fog::%<service>s::%<provider>s. The
preferred format of service provider constants has changed from
service::provider to provider::service. Please update this service
provider to use the preferred format.
EOS
E_SERVICE_PROVIDER_PATH = <<-EOS.gsub(/\s+/, ' ').strip.freeze
Falling back to deprecated path fog/%<service>s/%<provider>s. The
preferred file path format has changed from service/provider to
provider/service. Please update this service provider to use the preferred
format.
EOS

def [](provider)
new(:provider => provider)
end
Expand Down Expand Up @@ -32,15 +45,19 @@ 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("Unable to require fog/#{provider}/#{service}")
Fog::Logger.deprecation("The format fog/#{service}/#{provider} is deprecated")
Fog::Logger.deprecation(
format(E_SERVICE_PROVIDER_PATH, service: service, provider: provider)
)
require "fog/#{service}/#{provider}"
end

def service_provider_constant(service_name, provider_name)
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("Unable to load Fog::#{provider_name}::#{service_name}")
Fog::Logger.deprecation("The format Fog::#{service_name}::#{provider_name} is deprecated")
Fog::Logger.deprecation(
format(E_SERVICE_PROVIDER_CONSTANT, service: service_name, provider: provider_name)
)
Fog.const_get(service_name).const_get(*const_get_args(provider_name))
end

Expand Down