Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: fog/fog
base: 808e576604
...
head fork: fog/fog
compare: f1a2701fa1
  • 2 commits
  • 43 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 23, 2012
@tokengeek tokengeek Make use of #persisted? method
In many places we were checking for identity which was the shorthand for
checking if the resource had been saved by the service.

The #persisted? method was added to show a clearer intent and also offer
minimal ActiveModel interface
40c0cd7
Commits on Dec 27, 2012
@tokengeek tokengeek Merge pull request #1416 from fog/use_persisted
Make use of #persisted? method
f1a2701
Showing with 46 additions and 46 deletions.
  1. +1 −1  lib/fog/aws/models/cdn/invalidation.rb
  2. +1 −1  lib/fog/aws/models/compute/address.rb
  3. +2 −2 lib/fog/aws/models/compute/server.rb
  4. +1 −1  lib/fog/aws/models/compute/snapshot.rb
  5. +1 −1  lib/fog/aws/models/compute/volume.rb
  6. +2 −2 lib/fog/bluebox/models/compute/server.rb
  7. +1 −1  lib/fog/brightbox/models/compute/api_client.rb
  8. +1 −1  lib/fog/brightbox/models/compute/application.rb
  9. +1 −1  lib/fog/brightbox/models/compute/firewall_policy.rb
  10. +1 −1  lib/fog/brightbox/models/compute/firewall_rule.rb
  11. +1 −1  lib/fog/brightbox/models/compute/image.rb
  12. +1 −1  lib/fog/brightbox/models/compute/load_balancer.rb
  13. +2 −2 lib/fog/brightbox/models/compute/server.rb
  14. +1 −1  lib/fog/clodo/models/compute/server.rb
  15. +1 −1  lib/fog/go_grid/models/compute/image.rb
  16. +1 −1  lib/fog/go_grid/models/compute/password.rb
  17. +1 −1  lib/fog/go_grid/models/compute/server.rb
  18. +1 −1  lib/fog/hp/models/compute/address.rb
  19. +1 −1  lib/fog/hp/models/compute/server.rb
  20. +1 −1  lib/fog/ibm/models/storage/volume.rb
  21. +1 −1  lib/fog/linode/models/compute/disk.rb
  22. +1 −1  lib/fog/linode/models/compute/ip.rb
  23. +1 −1  lib/fog/linode/models/compute/server.rb
  24. +1 −1  lib/fog/openstack/models/compute/address.rb
  25. +1 −1  lib/fog/openstack/models/compute/server.rb
  26. +1 −1  lib/fog/openstack/models/identity/user.rb
  27. +1 −1  lib/fog/ovirt/models/compute/server.rb
  28. +1 −1  lib/fog/ovirt/models/compute/template.rb
  29. +1 −1  lib/fog/rackspace/models/block_storage/snapshot.rb
  30. +1 −1  lib/fog/rackspace/models/block_storage/volume.rb
  31. +1 −1  lib/fog/rackspace/models/compute/image.rb
  32. +1 −1  lib/fog/rackspace/models/compute/server.rb
  33. +1 −1  lib/fog/rackspace/models/compute_v2/server.rb
  34. +1 −1  lib/fog/rackspace/models/dns/record.rb
  35. +1 −1  lib/fog/rackspace/models/dns/zone.rb
  36. +1 −1  lib/fog/rackspace/models/identity/user.rb
  37. +1 −1  lib/fog/rackspace/models/load_balancers/access_rule.rb
  38. +1 −1  lib/fog/rackspace/models/load_balancers/load_balancer.rb
  39. +1 −1  lib/fog/rackspace/models/load_balancers/node.rb
  40. +1 −1  lib/fog/rackspace/models/load_balancers/virtual_ip.rb
  41. +1 −1  lib/fog/voxel/models/compute/server.rb
  42. +1 −1  lib/fog/vsphere/models/compute/server.rb
  43. +1 −1  lib/fog/zerigo/models/dns/record.rb
View
2  lib/fog/aws/models/cdn/invalidation.rb
@@ -29,7 +29,7 @@ def ready?
def save
requires :paths, :caller_reference
- raise "Submitted invalidation cannot be submitted again" if identity
+ raise "Submitted invalidation cannot be submitted again" if persisted?
response = connection.post_invalidation(distribution.identity, paths, caller_reference)
merge_attributes(invalidation_to_attributes(response.body))
true
View
2  lib/fog/aws/models/compute/address.rb
@@ -39,7 +39,7 @@ def server
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
data = connection.allocate_address(domain).body
new_attributes = data.reject {|key,value| key == 'requestId'}
merge_attributes(new_attributes)
View
4 lib/fog/aws/models/compute/server.rb
@@ -130,7 +130,7 @@ def reboot
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :image_id
options = {
@@ -224,7 +224,7 @@ def volumes
#but in #save a merge_attribute is called after run_instance
#thus making an un-necessary request. Use this until finding a clever solution
def monitor=(new_monitor)
- if identity
+ if persisted?
case new_monitor
when true
response = connection.monitor_instances(identity)
View
2  lib/fog/aws/models/compute/snapshot.rb
@@ -29,7 +29,7 @@ def ready?
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :volume_id
data = connection.create_snapshot(volume_id, description).body
View
2  lib/fog/aws/models/compute/volume.rb
@@ -39,7 +39,7 @@ def ready?
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :availability_zone
requires_one :size, :snapshot_id
View
4 lib/fog/bluebox/models/compute/server.rb
@@ -71,11 +71,11 @@ def reboot(type = 'SOFT')
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :flavor_id, :image_id, :location_id
options = {}
- if identity.nil? # new record
+ unless persisted? # new record
raise(ArgumentError, "password or public_key is required for this operation") if !password && !public_key
options['ssh_public_key'] = public_key if public_key
options['password'] = password if @password
View
2  lib/fog/brightbox/models/compute/api_client.rb
@@ -10,7 +10,7 @@ class ApiClient < Fog::Model
attribute :account_id
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
options = {
:name => name,
:description => description
View
2  lib/fog/brightbox/models/compute/application.rb
@@ -12,7 +12,7 @@ class Application < Fog::Model
attribute :secret
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
options = {
:name => name
}.delete_if {|k,v| v.nil? || v == "" }
View
2  lib/fog/brightbox/models/compute/firewall_policy.rb
@@ -21,7 +21,7 @@ class FirewallPolicy < Fog::Model
# Sticking with existing Fog behaviour, save does not update but creates a new resource
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
options = {
:server_group => server_group_id,
:name => name,
View
2  lib/fog/brightbox/models/compute/firewall_rule.rb
@@ -24,7 +24,7 @@ class FirewallRule < Fog::Model
# Sticking with existing Fog behaviour, save does not update but creates a new resource
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :firewall_policy_id
options = {
:firewall_policy => firewall_policy_id,
View
2  lib/fog/brightbox/models/compute/image.rb
@@ -39,7 +39,7 @@ def ready?
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :source, :arch
options = {
:source => source,
View
2  lib/fog/brightbox/models/compute/load_balancer.rb
@@ -32,7 +32,7 @@ def ready?
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :nodes, :listeners, :healthcheck
options = {
:nodes => nodes,
View
4 lib/fog/brightbox/models/compute/server.rb
@@ -164,7 +164,7 @@ def activate_console
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :image_id
options = {
:image => image_id,
@@ -198,7 +198,7 @@ def soft_reboot
# FIXME Using side effect of wait_for's (evaluated block) to detect timeouts
begin
wait_for(20) { ! ready? }
- start
+ start
rescue Fog::Errors::Timeout => e
false
end
View
2  lib/fog/clodo/models/compute/server.rb
@@ -88,7 +88,7 @@ def reboot(type = 'SOFT')
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :image_id
data = connection.create_server(image_id, attributes)
merge_attributes(data.body['server'])
View
2  lib/fog/go_grid/models/compute/image.rb
@@ -45,7 +45,7 @@ def ready?
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :server_id
data = connection.grid_server_add(server_id, 'name' => name)
View
2  lib/fog/go_grid/models/compute/password.rb
@@ -35,7 +35,7 @@ def ready?
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :password_id
data = connection.support_password_list()
merge_attributes(data.body)
View
2  lib/fog/go_grid/models/compute/server.rb
@@ -58,7 +58,7 @@ def reload
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :name, :image_id, :memory, :public_ip_address
options = {
'isSandbox' => sandbox,
View
2  lib/fog/hp/models/compute/address.rb
@@ -34,7 +34,7 @@ def server=(new_server)
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
data = connection.allocate_address.body['floating_ip']
new_attributes = data.reject {|key,value| !['id', 'instance_id', 'ip', 'fixed_ip'].include?(key)}
merge_attributes(new_attributes)
View
2  lib/fog/hp/models/compute/server.rb
@@ -161,7 +161,7 @@ def create_image(name, metadata={})
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :flavor_id, :image_id, :name
options = {
'metadata' => metadata,
View
2  lib/fog/ibm/models/storage/volume.rb
@@ -81,7 +81,7 @@ def ready?
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :name, :offering_id, :format, :location_id, :size
data = connection.create_volume(name, offering_id, format, location_id, size)
merge_attributes(data.body)
View
2  lib/fog/linode/models/compute/disk.rb
@@ -10,7 +10,7 @@ class Disk < Fog::Model
def save
requires :server
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
@type, @image, @stack_script, @name, @password, @size =
attributes.values_at :type, :image, :stack_script, :name, :password, :size
create_disk
View
2  lib/fog/linode/models/compute/ip.rb
@@ -10,7 +10,7 @@ class Ip < Fog::Model
def save
requires :server
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
connection.linode_ip_addprivate server.id
server.ips.all.find { |ip| !ip.public }
View
2  lib/fog/linode/models/compute/server.rb
@@ -43,7 +43,7 @@ def boot
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
@data_center, @flavor, @image, @kernel, @type, @payment_terms, @stack_script, @name, @password, @callback =
attributes.values_at :data_center, :flavor, :image, :kernel, :type, :payment_terms, :stack_script, :name, :password, :callback
View
2  lib/fog/openstack/models/compute/address.rb
@@ -34,7 +34,7 @@ def server=(new_server)
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
data = connection.allocate_address(pool).body['floating_ip']
new_attributes = data.reject {|key,value| !['id', 'instance_id', 'ip', 'fixed_ip'].include?(key)}
merge_attributes(new_attributes)
View
2  lib/fog/openstack/models/compute/server.rb
@@ -226,7 +226,7 @@ def networks
# TODO: Implement /os-volumes-boot support with 'block_device_mapping'
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :flavor_ref, :image_ref, :name
meta_hash = {}
metadata.each { |meta| meta_hash.store(meta.key, meta.value) }
View
2  lib/fog/openstack/models/identity/user.rb
@@ -25,7 +25,7 @@ def ec2_credentials
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :name, :tenant_id, :password
enabled = true if enabled.nil?
data = connection.create_user(name, password, email, tenant_id, enabled)
View
2  lib/fog/ovirt/models/compute/server.rb
@@ -116,7 +116,7 @@ def ticket(options = {})
end
def save
- if identity
+ if persisted?
connection.update_vm(attributes)
else
self.id = connection.create_vm(attributes).id
View
2  lib/fog/ovirt/models/compute/template.rb
@@ -45,7 +45,7 @@ def destroy(options = {})
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
connection.client.create_template(attributes)
end
View
2  lib/fog/rackspace/models/block_storage/snapshot.rb
@@ -26,7 +26,7 @@ def ready?
def save(force = false)
requires :volume_id
- raise IdentifierTaken.new('Resaving may cause a duplicate snapshot to be created') if identity
+ raise IdentifierTaken.new('Resaving may cause a duplicate snapshot to be created') if persisted?
data = connection.create_snapshot(volume_id, {
:display_name => display_name,
:display_description => display_description,
View
2  lib/fog/rackspace/models/block_storage/volume.rb
@@ -42,7 +42,7 @@ def create_snapshot(options={})
def save
requires :size
- raise IdentifierTaken.new('Resaving may cause a duplicate volume to be created') if identity
+ raise IdentifierTaken.new('Resaving may cause a duplicate volume to be created') if persisted?
data = connection.create_volume(size, {
:display_name => display_name,
:display_description => display_description,
View
2  lib/fog/rackspace/models/compute/image.rb
@@ -33,7 +33,7 @@ def ready?
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :server_id
data = connection.create_image(server_id, 'name' => name)
View
2  lib/fog/rackspace/models/compute/server.rb
@@ -66,7 +66,7 @@ def reboot(type = 'SOFT')
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :flavor_id, :image_id
options = {
'metadata' => metadata,
View
2  lib/fog/rackspace/models/compute_v2/server.rb
@@ -45,7 +45,7 @@ class Server < Fog::Compute::Server
attr_reader :password
def save
- if identity
+ if persisted?
update
else
create
View
2  lib/fog/rackspace/models/dns/record.rb
@@ -33,7 +33,7 @@ def zone
end
def save
- if identity
+ if persisted?
update
else
create
View
2  lib/fog/rackspace/models/dns/zone.rb
@@ -35,7 +35,7 @@ def records
end
def save
- if identity
+ if persisted?
update
else
create
View
2  lib/fog/rackspace/models/identity/user.rb
@@ -15,7 +15,7 @@ class User < Fog::Model
def save
requires :username, :email, :enabled
- if identity.nil?
+ unless persisted?
data = connection.create_user(username, email, enabled, :password => password)
else
data = connection.update_user(identity, username, email, enabled, :password => password)
View
2  lib/fog/rackspace/models/load_balancers/access_rule.rb
@@ -17,7 +17,7 @@ def destroy
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :load_balancer, :address, :type
connection.create_access_rule(load_balancer.id, address, type)
View
2  lib/fog/rackspace/models/load_balancers/load_balancer.rb
@@ -164,7 +164,7 @@ def ready?
end
def save
- if identity
+ if persisted?
update
else
create
View
2  lib/fog/rackspace/models/load_balancers/node.rb
@@ -20,7 +20,7 @@ def destroy
end
def save
- if identity
+ if persisted?
update
else
create
View
2  lib/fog/rackspace/models/load_balancers/virtual_ip.rb
@@ -18,7 +18,7 @@ def destroy
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :load_balancer, :type
data = connection.create_virtual_ip(load_balancer.id, type)
merge_attributes(data.body)
View
2  lib/fog/voxel/models/compute/server.rb
@@ -54,7 +54,7 @@ def state
end
def save
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :name, :image_id, :processing_cores, :facility, :disk_size
data = connection.voxcloud_create({
View
2  lib/fog/vsphere/models/compute/server.rb
@@ -165,7 +165,7 @@ def folder
def save
requires :name, :cluster, :datacenter
- if identity
+ if persisted?
raise "update is not supported yet"
# connection.update_vm(attributes)
else
View
2  lib/fog/zerigo/models/dns/record.rb
@@ -45,7 +45,7 @@ def save
options[:priority] = priority if priority
options[:ttl] = ttl if ttl
- if identity
+ if persisted?
options[:host_type] = type
options[:data] = value
connection.update_host(identity, options)

No commit comments for this range

Something went wrong with that request. Please try again.