mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[core] Deprecates 'connection' accessor
The 'connection' accessor in collections and models actually refered to a subclassed instance of Fog::Service which creates confusion in the code. References to 'connection' could have meant the service or the Fog::Connection held within that service. This deprecates the connection accessor and replaces it with `#service` as a read only value. When a collection or model is initalised then service should be passed. This commit also updates all the changes to @connection made by providers in model initialisers since these depending on the presence of the 'connection' key. The key is still accepted by outputs a warning.
This commit is contained in:
parent
05dffba5bf
commit
7961ad6508
22 changed files with 122 additions and 38 deletions
|
@ -12,25 +12,25 @@ module Fog
|
|||
def files
|
||||
@files ||= begin
|
||||
Fog::Storage::Atmos::Files.new(
|
||||
:directory => self,
|
||||
:connection => connection
|
||||
)
|
||||
end
|
||||
:directory => self,
|
||||
:service => service
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def directories
|
||||
@directories ||= begin
|
||||
Fog::Storage::Atmos::Directories.new(
|
||||
:directory => self,
|
||||
:connection => connection
|
||||
)
|
||||
end
|
||||
Fog::Storage::Atmos::Directories.new(
|
||||
:directory => self,
|
||||
:service => service
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def save
|
||||
self.key = attributes[:directory].key + key if attributes[:directory]
|
||||
self.key = key + '/' unless key =~ /\/$/
|
||||
res = connection.post_namespace key
|
||||
res = service.post_namespace key
|
||||
reload
|
||||
end
|
||||
|
||||
|
@ -42,7 +42,7 @@ module Fog
|
|||
d.destroy(opts)
|
||||
end
|
||||
end
|
||||
connection.delete_namespace key
|
||||
service.delete_namespace key
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -53,9 +53,13 @@ module Fog
|
|||
def initialize(attributes={})
|
||||
self.groups ||= ["default"] unless (attributes[:subnet_id] || attributes[:security_group_ids])
|
||||
self.flavor_id ||= 't1.micro'
|
||||
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
prepare_service_value(attributes)
|
||||
|
||||
self.image_id ||= begin
|
||||
self.username = 'ubuntu'
|
||||
case attributes[:connection].instance_variable_get(:@region) # Ubuntu 10.04 LTS 64bit (EBS)
|
||||
case @service.instance_variable_get(:@region) # Ubuntu 10.04 LTS 64bit (EBS)
|
||||
when 'ap-northeast-1'
|
||||
'ami-5e0fa45f'
|
||||
when 'ap-southeast-1'
|
||||
|
|
|
@ -43,7 +43,11 @@ module Fog
|
|||
self.flavor_id ||= 't1.micro'
|
||||
self.image_id ||= begin
|
||||
self.username = 'ubuntu'
|
||||
case attributes[:connection].instance_variable_get(:@region) # Ubuntu 10.04 LTS 64bit (EBS)
|
||||
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
prepare_service_value(attributes)
|
||||
|
||||
case @service.instance_variable_get(:@region) # Ubuntu 10.04 LTS 64bit (EBS)
|
||||
when 'ap-northeast-1'
|
||||
'ami-5e0fa45f'
|
||||
when 'ap-southeast-1'
|
||||
|
|
|
@ -194,7 +194,7 @@ module Fog
|
|||
|
||||
def missing_attributes(args)
|
||||
missing = []
|
||||
for arg in [:connection] | args
|
||||
for arg in [:service] | args
|
||||
unless send("#{arg}") || attributes.has_key?(arg)
|
||||
missing << arg
|
||||
end
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
require "fog/core/deprecated_connection_accessors"
|
||||
|
||||
module Fog
|
||||
class Collection < Array
|
||||
|
||||
extend Fog::Attributes::ClassMethods
|
||||
include Fog::Attributes::InstanceMethods
|
||||
include Fog::Core::DeprecatedConnectionAccessors
|
||||
|
||||
attr_reader :service
|
||||
|
||||
Array.public_instance_methods(false).each do |method|
|
||||
unless [:reject, :select, :slice].include?(method.to_sym)
|
||||
|
@ -37,8 +41,6 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
attr_accessor :connection
|
||||
|
||||
remove_method :clear
|
||||
def clear
|
||||
@loaded = true
|
||||
|
@ -56,11 +58,20 @@ module Fog
|
|||
object.destroy
|
||||
end
|
||||
|
||||
# Creates a new Fog::Collection based around the passed service
|
||||
#
|
||||
# @param [Hash] attributes
|
||||
# @option attributes [Fog::Service] service Instance of a service
|
||||
#
|
||||
# @return [Fog::Collection]
|
||||
#
|
||||
def initialize(attributes = {})
|
||||
@service = attributes.delete(:service)
|
||||
@loaded = false
|
||||
merge_attributes(attributes)
|
||||
end
|
||||
|
||||
|
||||
remove_method :inspect
|
||||
def inspect
|
||||
Thread.current[:formatador] ||= Formatador.new
|
||||
|
@ -105,7 +116,7 @@ module Fog
|
|||
model.new(
|
||||
{
|
||||
:collection => self,
|
||||
:connection => connection
|
||||
:service => service
|
||||
}.merge(attributes)
|
||||
)
|
||||
end
|
||||
|
|
41
lib/fog/core/deprecated_connection_accessors.rb
Normal file
41
lib/fog/core/deprecated_connection_accessors.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
module Fog
|
||||
module Core
|
||||
# This module covers the shared code used by models and collections
|
||||
# that deprecates the confusing usage of 'connection' which was
|
||||
# actually intended to be an instance of Fog::Service
|
||||
module DeprecatedConnectionAccessors
|
||||
# Sets the Service but using the wrong name!
|
||||
#
|
||||
# @deprecated The connection name was wrong and confusing since it refered to the service
|
||||
# @param [Fog::Service] service An instance of a Fog service this collection is for
|
||||
#
|
||||
def connection=(service)
|
||||
Fog::Logger.deprecation("#connection= is deprecated, pass :service in at creation [light_black](#{caller.first})[/]")
|
||||
@service = service
|
||||
end
|
||||
|
||||
# Returns the Service the collection is part of
|
||||
#
|
||||
# @deprecated #connection is deprecated due to confusing name, use #service instead
|
||||
# @return [Fog::Service]
|
||||
#
|
||||
def connection
|
||||
Fog::Logger.deprecation("#connection is deprecated, use #service instead [light_black](#{caller.first})[/]")
|
||||
@service
|
||||
end
|
||||
|
||||
# Prepares the value of the service based on the passed attributes
|
||||
#
|
||||
# @note Intended for use where the service is required before the normal
|
||||
# initializer runs. The logic is run there with deprecation warnings.
|
||||
#
|
||||
# @param [Hash] attributes
|
||||
# @return [Fog::Service]
|
||||
#
|
||||
def prepare_service_value(attributes)
|
||||
@service = attributes[:service] || attributes[:connection]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,12 +1,22 @@
|
|||
require "fog/core/deprecated_connection_accessors"
|
||||
|
||||
module Fog
|
||||
class Model
|
||||
|
||||
extend Fog::Attributes::ClassMethods
|
||||
include Fog::Attributes::InstanceMethods
|
||||
include Fog::Core::DeprecatedConnectionAccessors
|
||||
|
||||
attr_accessor :collection, :connection
|
||||
attr_accessor :collection
|
||||
attr_reader :service
|
||||
|
||||
def initialize(new_attributes = {})
|
||||
# TODO Remove compatibility with old connection option
|
||||
@service = @service || new_attributes.delete(:service)
|
||||
if @service.nil? && new_attributes[:connection]
|
||||
Fog::Logger.deprecation("Passing :connection option is deprecated, use :service instead [light_black](#{caller.first})[/]")
|
||||
@service = new_attributes[:connection]
|
||||
end
|
||||
merge_attributes(new_attributes)
|
||||
end
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ module Fog
|
|||
constant = collection.to_s.split('_').map {|characters| characters[0...1].upcase << characters[1..-1]}.join('')
|
||||
service::Collections.module_eval <<-EOS, __FILE__, __LINE__
|
||||
def #{collection}(attributes = {})
|
||||
#{service}::#{constant}.new({:connection => self}.merge(attributes))
|
||||
#{service}::#{constant}.new({:service => self}.merge(attributes))
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
|
|
@ -18,7 +18,8 @@ module Fog
|
|||
attribute :disabled, :aliases => 'OS-FLV-DISABLED:disabled'
|
||||
|
||||
def initialize(attributes)
|
||||
@connection = attributes[:connection]
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
prepare_service_value(attributes)
|
||||
super
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@ module Fog
|
|||
attribute :details
|
||||
|
||||
def initialize(attributes)
|
||||
@connection = attributes[:connection]
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
prepare_service_value(attributes)
|
||||
super
|
||||
end
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@ module Fog
|
|||
attribute :links
|
||||
|
||||
def initialize(attributes)
|
||||
@connection = attributes[:connection]
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
prepare_service_value(attributes)
|
||||
super
|
||||
end
|
||||
|
||||
|
|
|
@ -44,7 +44,8 @@ module Fog
|
|||
|
||||
|
||||
def initialize(attributes={})
|
||||
@connection = attributes[:connection]
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
prepare_service_value(attributes)
|
||||
attributes[:metadata] = {}
|
||||
|
||||
self.security_groups = attributes.delete(:security_groups)
|
||||
|
|
|
@ -18,7 +18,8 @@ module Fog
|
|||
|
||||
|
||||
def initialize(attributes)
|
||||
@connection = attributes[:connection]
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
prepare_service_value(attributes)
|
||||
super
|
||||
end
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@ module Fog
|
|||
|
||||
|
||||
def initialize(attributes)
|
||||
@connection = attributes[:connection]
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
prepare_service_value(attributes)
|
||||
super
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,8 @@ module Fog
|
|||
attribute :user_id
|
||||
|
||||
def initialize(attributes)
|
||||
@connection = attributes[:connection]
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
prepare_service_value(attributes)
|
||||
super
|
||||
end
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@ module Fog
|
|||
attr_accessor :email, :name, :tenant_id, :enabled, :password
|
||||
|
||||
def initialize(attributes)
|
||||
@connection = attributes[:connection]
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
prepare_service_value(attributes)
|
||||
super
|
||||
end
|
||||
|
||||
|
|
|
@ -32,7 +32,8 @@ module Fog
|
|||
|
||||
|
||||
def initialize(attributes)
|
||||
@connection = attributes[:connection]
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
prepare_service_value(attributes)
|
||||
super
|
||||
end
|
||||
|
||||
|
|
|
@ -14,7 +14,8 @@ module Fog
|
|||
attribute :tenant_id
|
||||
|
||||
def initialize(attributes)
|
||||
@connection = attributes[:connection]
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
prepare_service_value(attributes)
|
||||
super
|
||||
end
|
||||
|
||||
|
@ -43,4 +44,4 @@ module Fog
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,7 +17,8 @@ module Fog
|
|||
attribute :tenant_id
|
||||
|
||||
def initialize(attributes)
|
||||
@connection = attributes[:connection]
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
prepare_service_value(attributes)
|
||||
super
|
||||
end
|
||||
|
||||
|
@ -49,4 +50,4 @@ module Fog
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,8 @@ module Fog
|
|||
attribute :tenant_id
|
||||
|
||||
def initialize(attributes)
|
||||
@connection = attributes[:connection]
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
prepare_service_value(attributes)
|
||||
super
|
||||
end
|
||||
|
||||
|
@ -52,4 +53,4 @@ module Fog
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,7 +20,8 @@ module Fog
|
|||
|
||||
|
||||
def initialize(attributes)
|
||||
@connection = attributes[:connection]
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
prepare_service_value(attributes)
|
||||
super
|
||||
end
|
||||
|
||||
|
|
|
@ -29,8 +29,9 @@ module Fog
|
|||
attribute :nodes
|
||||
|
||||
def initialize(attributes)
|
||||
#HACK - Since we are hacking how sub-collections work, we have to make sure the connection is valid first.
|
||||
@connection = attributes[:connection]
|
||||
#HACK - Since we are hacking how sub-collections work, we have to make sure the service is valid first.
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
@service = attributes[:service] || attributes[:connection]
|
||||
super
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue