1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

update attribute to consistently take hash and remove legacy array of aliases usage

This commit is contained in:
geemus 2010-09-07 11:30:02 -07:00
parent d7c31672d6
commit 6d6eafbb2b
19 changed files with 98 additions and 102 deletions

View file

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

View file

@ -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?

View file

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

View file

@ -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

View file

@ -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

View file

@ -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={})

View file

@ -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

View file

@ -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?

View file

@ -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

View file

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

View file

@ -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

View file

@ -9,7 +9,7 @@ module Fog
attribute :description
attribute :public
attribute :created_at, 'created'
attribute :created_at, :aliases => 'created'
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -8,7 +8,7 @@ module Fog
identity :id
attribute :ip, 'name'
attribute :ip, :aliases => 'name'
def destroy
requires :id

View file

@ -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')