From 6d6eafbb2b839dcfbbb758dff1770a5c0b779600 Mon Sep 17 00:00:00 2001
From: geemus <geemus@gmail.com>
Date: Tue, 7 Sep 2010 11:30:02 -0700
Subject: [PATCH] update attribute to consistently take hash and remove legacy
 array of aliases usage

---
 lib/fog/attributes.rb                      |  8 ++---
 lib/fog/aws/models/ec2/address.rb          |  4 +--
 lib/fog/aws/models/ec2/image.rb            | 24 +++++++-------
 lib/fog/aws/models/ec2/key_pair.rb         |  6 ++--
 lib/fog/aws/models/ec2/security_group.rb   |  8 ++---
 lib/fog/aws/models/ec2/server.rb           | 38 +++++++++++-----------
 lib/fog/aws/models/ec2/snapshot.rb         | 12 +++----
 lib/fog/aws/models/ec2/volume.rb           | 14 ++++----
 lib/fog/aws/models/s3/directory.rb         |  4 +--
 lib/fog/aws/models/s3/file.rb              | 16 ++++-----
 lib/fog/aws/models/s3/files.rb             | 10 +++---
 lib/fog/bluebox/models/image.rb            |  2 +-
 lib/fog/local/models/file.rb               |  6 ++--
 lib/fog/rackspace/models/files/file.rb     | 10 +++---
 lib/fog/rackspace/models/servers/image.rb  |  6 ++--
 lib/fog/rackspace/models/servers/server.rb |  6 ++--
 lib/fog/slicehost/models/server.rb         | 12 +++----
 lib/fog/terremark/models/shared/address.rb |  2 +-
 lib/fog/terremark/models/shared/task.rb    | 12 +++----
 19 files changed, 98 insertions(+), 102 deletions(-)

diff --git a/lib/fog/attributes.rb b/lib/fog/attributes.rb
index 2d6bc39a1..f22151111 100644
--- a/lib/fog/attributes.rb
+++ b/lib/fog/attributes.rb
@@ -15,10 +15,6 @@ module Fog
       end
 
       def attribute(name, options = {})
-        # FIXME: handle legacy where options would have been one or more aliases
-        if !options.is_a?(Hash)
-          options = {:aliases => options}
-        end
         class_eval <<-EOS, __FILE__, __LINE__
           attr_reader :#{name}
         EOS
@@ -100,9 +96,9 @@ module Fog
         end
       end
 
-      def identity(name, other_names = [])
+      def identity(name, options = {})
         @identity = name
-        self.attribute(name, {:aliases => other_names})
+        self.attribute(name, options)
       end
 
       def ignore_attributes(*args)
diff --git a/lib/fog/aws/models/ec2/address.rb b/lib/fog/aws/models/ec2/address.rb
index b7fa193aa..930be42d6 100644
--- a/lib/fog/aws/models/ec2/address.rb
+++ b/lib/fog/aws/models/ec2/address.rb
@@ -6,9 +6,9 @@ module Fog
 
       class Address < Fog::Model
 
-        identity  :public_ip,   'publicIp'
+        identity  :public_ip, :aliases => 'publicIp'
 
-        attribute :server_id, 'instanceId'
+        attribute :server_id, :aliases => 'instanceId'
 
         def initialize(attributes = {})
           # assign server first to prevent race condition with new_record?
diff --git a/lib/fog/aws/models/ec2/image.rb b/lib/fog/aws/models/ec2/image.rb
index 2c03c63e2..2bd11880d 100644
--- a/lib/fog/aws/models/ec2/image.rb
+++ b/lib/fog/aws/models/ec2/image.rb
@@ -6,21 +6,21 @@ module Fog
 
       class Image < Fog::Model
 
-        identity :id,                    'imageId'
+        identity :id,                     :aliases => 'imageId'
 
         attribute :architecture
-        attribute :block_device_mapping, 'blockDeviceMapping'
-        attribute :location,             'imageLocation'
-        attribute :owner_id,             'imageOwnerId'
-        attribute :state,                'imageState'
-        attribute :type,                 'imageType'
-        attribute :is_public,            'isPublic'
-        attribute :kernel_id,            'kernelId'
+        attribute :block_device_mapping,  :aliases => 'blockDeviceMapping'
+        attribute :location,              :aliases => 'imageLocation'
+        attribute :owner_id,              :aliases => 'imageOwnerId'
+        attribute :state,                 :aliases => 'imageState'
+        attribute :type,                  :aliases => 'imageType'
+        attribute :is_public,             :aliases => 'isPublic'
+        attribute :kernel_id,             :aliases => 'kernelId'
         attribute :platform
-        attribute :product_codes,        'productCodes'
-        attribute :ramdisk_id,           'ramdiskId'
-        attribute :root_device_type,     'rootDeviceType'
-        attribute :root_device_name,     'rootDeviceName'
+        attribute :product_codes,         :aliases => 'productCodes'
+        attribute :ramdisk_id,            :aliases => 'ramdiskId'
+        attribute :root_device_type,      :aliases => 'rootDeviceType'
+        attribute :root_device_name,      :aliases => 'rootDeviceName'
 
         def deregister(delete_snapshot = false)
           connection.deregister_image(@id)
diff --git a/lib/fog/aws/models/ec2/key_pair.rb b/lib/fog/aws/models/ec2/key_pair.rb
index 6982f1ac9..5274904f5 100644
--- a/lib/fog/aws/models/ec2/key_pair.rb
+++ b/lib/fog/aws/models/ec2/key_pair.rb
@@ -6,10 +6,10 @@ module Fog
 
       class KeyPair < Fog::Model
 
-        identity  :name,        'keyName'
+        identity  :name,        :aliases => 'keyName'
 
-        attribute :fingerprint, 'keyFingerprint'
-        attribute :material,    'keyMaterial'
+        attribute :fingerprint, :aliases => 'keyFingerprint'
+        attribute :material,    :aliases => 'keyMaterial'
 
         def destroy
           requires :name
diff --git a/lib/fog/aws/models/ec2/security_group.rb b/lib/fog/aws/models/ec2/security_group.rb
index 29058cc07..91a9e83f6 100644
--- a/lib/fog/aws/models/ec2/security_group.rb
+++ b/lib/fog/aws/models/ec2/security_group.rb
@@ -6,11 +6,11 @@ module Fog
 
       class SecurityGroup < Fog::Model
 
-        identity  :name,            'groupName'
+        identity  :name,            :aliases => 'groupName'
 
-        attribute :description,     'groupDescription'
-        attribute :ip_permissions,  'ipPermissions'
-        attribute :owner_id,        'ownerId'
+        attribute :description,     :aliases => 'groupDescription'
+        attribute :ip_permissions,  :aliases => 'ipPermissions'
+        attribute :owner_id,        :aliases => 'ownerId'
 
         def authorize_group_and_owner(group, owner)
           requires :name
diff --git a/lib/fog/aws/models/ec2/server.rb b/lib/fog/aws/models/ec2/server.rb
index 4139cbfee..2179c034d 100644
--- a/lib/fog/aws/models/ec2/server.rb
+++ b/lib/fog/aws/models/ec2/server.rb
@@ -6,30 +6,30 @@ module Fog
 
       class Server < Fog::Model
 
-        identity  :id,                    'instanceId'
+        identity  :id,                    :aliases => 'instanceId'
 
         attr_accessor :architecture
-        attribute :ami_launch_index,      'amiLaunchIndex'
-        attribute :availability_zone,     'availabilityZone'
-        attribute :block_device_mapping,  'blockDeviceMapping'
-        attribute :dns_name,              'dnsName'
+        attribute :ami_launch_index,      :aliases => 'amiLaunchIndex'
+        attribute :availability_zone,     :aliases => 'availabilityZone'
+        attribute :block_device_mapping,  :aliases => 'blockDeviceMapping'
+        attribute :dns_name,              :aliases => 'dnsName'
         attribute :groups
-        attribute :flavor_id,             'instanceType'
-        attribute :image_id,              'imageId'
-        attribute :ip_address,            'ipAddress'
-        attribute :kernel_id,             'kernelId'
-        attribute :key_name,              'keyName'
-        attribute :created_at,            'launchTime'
+        attribute :flavor_id,             :aliases => 'instanceType'
+        attribute :image_id,              :aliases => 'imageId'
+        attribute :ip_address,            :aliases => 'ipAddress'
+        attribute :kernel_id,             :aliases => 'kernelId'
+        attribute :key_name,              :aliases => 'keyName'
+        attribute :created_at,            :aliases => 'launchTime'
         attribute :monitoring
-        attribute :product_codes,         'productCodes'
-        attribute :private_dns_name,      'privateDnsName'
-        attribute :private_ip_address,    'privateIpAddress'
-        attribute :ramdisk_id,            'ramdiskId'
+        attribute :product_codes,         :aliases => 'productCodes'
+        attribute :private_dns_name,      :aliases => 'privateDnsName'
+        attribute :private_ip_address,    :aliases => 'privateIpAddress'
+        attribute :ramdisk_id,            :aliases => 'ramdiskId'
         attribute :reason
-        attribute :root_device_name,      'rootDeviceName'
-        attribute :root_device_type,      'rootDeviceType'
-        attribute :state,                 'instanceState'
-        attribute :subnet_id,             'subnetId'
+        attribute :root_device_name,      :aliases => 'rootDeviceName'
+        attribute :root_device_type,      :aliases => 'rootDeviceType'
+        attribute :state,                 :aliases => 'instanceState'
+        attribute :subnet_id,             :aliases => 'subnetId'
         attribute :user_data
 
         def initialize(attributes={})
diff --git a/lib/fog/aws/models/ec2/snapshot.rb b/lib/fog/aws/models/ec2/snapshot.rb
index e823118d5..5b77a07b2 100644
--- a/lib/fog/aws/models/ec2/snapshot.rb
+++ b/lib/fog/aws/models/ec2/snapshot.rb
@@ -8,15 +8,15 @@ module Fog
         extend Fog::Deprecation
         deprecate(:status, :state)
 
-        identity  :id, 'snapshotId'
+        identity  :id,          :aliases => 'snapshotId'
 
         attribute :description
         attribute :progress
-        attribute :created_at,  'startTime'
-        attribute :owner_id,    'ownerId'
-        attribute :state,       'status'
-        attribute :volume_id,   'volumeId'
-        attribute :volume_size, 'volumeSize'
+        attribute :created_at,  :aliases => 'startTime'
+        attribute :owner_id,    :aliases => 'ownerId'
+        attribute :state,       :aliases => 'status'
+        attribute :volume_id,   :aliases => 'volumeId'
+        attribute :volume_size, :aliases => 'volumeSize'
 
         def destroy
           requires :id
diff --git a/lib/fog/aws/models/ec2/volume.rb b/lib/fog/aws/models/ec2/volume.rb
index 7fa339146..cb3cc3778 100644
--- a/lib/fog/aws/models/ec2/volume.rb
+++ b/lib/fog/aws/models/ec2/volume.rb
@@ -8,16 +8,16 @@ module Fog
         extend Fog::Deprecation
         deprecate(:status, :state)
 
-        identity  :id,         'volumeId'
+        identity  :id,                :aliases => 'volumeId'
 
-        attribute :attached_at,       'attachTime'
-        attribute :availability_zone, 'availabilityZone'
-        attribute :created_at,        'createTime'
+        attribute :attached_at,       :aliases => 'attachTime'
+        attribute :availability_zone, :aliases => 'availabilityZone'
+        attribute :created_at,        :aliases => 'createTime'
         attribute :device
-        attribute :server_id,         'instanceId'
+        attribute :server_id,         :aliases => 'instanceId'
         attribute :size
-        attribute :snapshot_id,       'snapshotId'
-        attribute :state,             'status'
+        attribute :snapshot_id,       :aliases => 'snapshotId'
+        attribute :state,             :aliases => 'status'
 
         def initialize(attributes = {})
           # assign server first to prevent race condition with new_record?
diff --git a/lib/fog/aws/models/s3/directory.rb b/lib/fog/aws/models/s3/directory.rb
index 969994497..67fc3aa91 100644
--- a/lib/fog/aws/models/s3/directory.rb
+++ b/lib/fog/aws/models/s3/directory.rb
@@ -10,9 +10,9 @@ module Fog
         deprecate(:name, :key)
         deprecate(:name=, :key=)
 
-        identity  :key,           ['Name', 'name']
+        identity  :key,           :aliases => ['Name', 'name']
 
-        attribute :creation_date, 'CreationDate'
+        attribute :creation_date, :aliases => 'CreationDate'
 
         def destroy
           requires :key
diff --git a/lib/fog/aws/models/s3/file.rb b/lib/fog/aws/models/s3/file.rb
index 6398a697c..a198bb6d3 100644
--- a/lib/fog/aws/models/s3/file.rb
+++ b/lib/fog/aws/models/s3/file.rb
@@ -6,16 +6,16 @@ module Fog
 
       class File < Fog::Model
 
-        identity  :key,             'Key'
+        identity  :key,             :aliases => 'Key'
 
         attr_accessor :body
-        attribute :content_length,  'Content-Length'
-        attribute :content_type,    'Content-Type'
-        attribute :etag,            ['Etag', 'ETag']
-        attribute :last_modified,   ['Last-Modified', 'LastModified']
-        attribute :owner,           'Owner'
-        attribute :size,            'Size'
-        attribute :storage_class,   'StorageClass'
+        attribute :content_length,  :aliases => 'Content-Length'
+        attribute :content_type,    :aliases => 'Content-Type'
+        attribute :etag,            :aliases => ['Etag', 'ETag']
+        attribute :last_modified,   :aliases => ['Last-Modified', 'LastModified']
+        attribute :owner,           :aliases => 'Owner'
+        attribute :size,            :aliases => 'Size'
+        attribute :storage_class,   :aliases => 'StorageClass'
 
         def body
           @body ||= if last_modified && (file = collection.get(identity))
diff --git a/lib/fog/aws/models/s3/files.rb b/lib/fog/aws/models/s3/files.rb
index e91dcbdea..a335ff82c 100644
--- a/lib/fog/aws/models/s3/files.rb
+++ b/lib/fog/aws/models/s3/files.rb
@@ -7,12 +7,12 @@ module Fog
 
       class Files < Fog::Collection
 
-        attribute :delimiter,     'Delimiter'
+        attribute :delimiter,     :aliases => 'Delimiter'
         attribute :directory
-        attribute :is_truncated,  'IsTruncated'
-        attribute :marker,        'Marker'
-        attribute :max_keys,      ['MaxKeys', 'max-keys']
-        attribute :prefix,        'Prefix'
+        attribute :is_truncated,  :aliases => 'IsTruncated'
+        attribute :marker,        :aliases => 'Marker'
+        attribute :max_keys,      :aliases => ['MaxKeys', 'max-keys']
+        attribute :prefix,        :aliases => 'Prefix'
 
         model Fog::AWS::S3::File
 
diff --git a/lib/fog/bluebox/models/image.rb b/lib/fog/bluebox/models/image.rb
index 8f28010de..68f4f8e80 100644
--- a/lib/fog/bluebox/models/image.rb
+++ b/lib/fog/bluebox/models/image.rb
@@ -9,7 +9,7 @@ module Fog
 
       attribute :description
       attribute :public
-      attribute :created_at, 'created'
+      attribute :created_at, :aliases => 'created'
 
     end
 
diff --git a/lib/fog/local/models/file.rb b/lib/fog/local/models/file.rb
index 70659a952..7e3dffef3 100644
--- a/lib/fog/local/models/file.rb
+++ b/lib/fog/local/models/file.rb
@@ -8,9 +8,9 @@ module Fog
       identity  :key,             'Key'
 
       attr_accessor :body
-      attribute :content_length,  'Content-Length'
-      # attribute :content_type,    'Content-Type'
-      attribute :last_modified,   'Last-Modified'
+      attribute :content_length,  :aliases => 'Content-Length'
+      # attribute :content_type,    :aliases => 'Content-Type'
+      attribute :last_modified,   :aliases => 'Last-Modified'
 
       def body
         @body ||= if last_modified
diff --git a/lib/fog/rackspace/models/files/file.rb b/lib/fog/rackspace/models/files/file.rb
index 18372f5e0..fe139564b 100644
--- a/lib/fog/rackspace/models/files/file.rb
+++ b/lib/fog/rackspace/models/files/file.rb
@@ -6,13 +6,13 @@ module Fog
 
       class File < Fog::Model
 
-        identity  :key,             'Key'
+        identity  :key,             :aliases => 'Key'
 
         attr_accessor :body
-        attribute :content_length,  'Content-Length'
-        attribute :content_type,    'Content-Type'
-        attribute :etag,            'Etag'
-        attribute :last_modified,   'Last-Modified'
+        attribute :content_length,  :aliases => 'Content-Length'
+        attribute :content_type,    :aliases => 'Content-Type'
+        attribute :etag,            :aliases => 'Etag'
+        attribute :last_modified,   :aliases => 'Last-Modified'
 
         def body
           @body ||= if last_modified
diff --git a/lib/fog/rackspace/models/servers/image.rb b/lib/fog/rackspace/models/servers/image.rb
index a4a18da3b..ab5d54f77 100644
--- a/lib/fog/rackspace/models/servers/image.rb
+++ b/lib/fog/rackspace/models/servers/image.rb
@@ -9,11 +9,11 @@ module Fog
         identity :id
 
         attribute :name
-        attribute :created_at,  'created'
-        attribute :updated_at,  'updated'
+        attribute :created_at,  :aliases => 'created'
+        attribute :updated_at,  :aliases => 'updated'
         attribute :progress
         attribute :status
-        attribute :server_id,   'serverId'
+        attribute :server_id,   :aliases => 'serverId'
 
         def server=(new_server)
           requires :id
diff --git a/lib/fog/rackspace/models/servers/server.rb b/lib/fog/rackspace/models/servers/server.rb
index 6b25bb6f2..c6969e859 100644
--- a/lib/fog/rackspace/models/servers/server.rb
+++ b/lib/fog/rackspace/models/servers/server.rb
@@ -9,9 +9,9 @@ module Fog
         identity :id
 
         attribute :addresses
-        attribute :flavor_id,   'flavorId'
-        attribute :host_id,     'hostId'
-        attribute :image_id,    'imageId'
+        attribute :flavor_id,   :aliases => 'flavorId'
+        attribute :host_id,     :aliases => 'hostId'
+        attribute :image_id,    :aliases => 'imageId'
         attribute :metadata
         attribute :name
         attribute :personality
diff --git a/lib/fog/slicehost/models/server.rb b/lib/fog/slicehost/models/server.rb
index 36939da23..d0b773acf 100644
--- a/lib/fog/slicehost/models/server.rb
+++ b/lib/fog/slicehost/models/server.rb
@@ -8,13 +8,13 @@ module Fog
       identity :id
 
       attribute :addresses
-      attribute :backup_id,     'backup-id'
-      attribute :bandwidth_in,  'bw-in'
-      attribute :bandwidth_out, 'bw-out'
-      attribute :flavor_id,     'flavor-id'
-      attribute :image_id,      'image-id'
+      attribute :backup_id,     :aliases => 'backup-id'
+      attribute :bandwidth_in,  :aliases => 'bw-in'
+      attribute :bandwidth_out, :aliases => 'bw-out'
+      attribute :flavor_id,     :aliases => 'flavor-id'
+      attribute :image_id,      :aliases => 'image-id'
       attribute :name
-      attribute :password,      'root-password'
+      attribute :password,      :aliases => 'root-password'
       attribute :progress
       attribute :status
 
diff --git a/lib/fog/terremark/models/shared/address.rb b/lib/fog/terremark/models/shared/address.rb
index 115b9cab1..4f3ccb7fd 100644
--- a/lib/fog/terremark/models/shared/address.rb
+++ b/lib/fog/terremark/models/shared/address.rb
@@ -8,7 +8,7 @@ module Fog
 
         identity :id
 
-        attribute :ip, 'name'
+        attribute :ip, :aliases => 'name'
 
         def destroy
          requires :id
diff --git a/lib/fog/terremark/models/shared/task.rb b/lib/fog/terremark/models/shared/task.rb
index 99c1895c4..150f66f0a 100644
--- a/lib/fog/terremark/models/shared/task.rb
+++ b/lib/fog/terremark/models/shared/task.rb
@@ -8,13 +8,13 @@ module Fog
 
         identity :id
 
-        attribute :end_time,    'endTime'
-        attribute :owner,       'Owner'
-        attribute :result,      'Result'
-        attribute :start_time,  'startTime'
+        attribute :end_time,    :aliases => 'endTime'
+        attribute :owner,       :aliases => 'Owner'
+        attribute :result,      :aliases => 'Result'
+        attribute :start_time,  :aliases => 'startTime'
         attribute :status
-        attribute :link,         'Link'
-        attribute :error,        'Error'
+        attribute :link,        :aliases => 'Link'
+        attribute :error,       :aliases => 'Error'
 
         def initialize(attributes = {})
           new_owner  = attributes.delete('Owner')