From bc09d7bbeedd751b25d68c70ffb67dd11986be5b Mon Sep 17 00:00:00 2001 From: Paul Thornthwaite Date: Mon, 17 Dec 2012 16:35:35 +0000 Subject: [PATCH] [core] Adds #persisted? to Fog models Fog models have been able to use #new_record? for years to use an ActiveRecord like interface to check for peristence of a resource. When Rails 3 switched to using ActiveModel API this changed to be #persisted? This deprecates #new_record? and adds #persisted? as the first little step to making fog models easier to use using ActiveModel API. As discussed on the tickes, ActiveModel is not planned to become a direct dependency for fog. Relates to #1276 --- lib/fog/core/attributes.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/fog/core/attributes.rb b/lib/fog/core/attributes.rb index ceadc8c3e..3abd63232 100644 --- a/lib/fog/core/attributes.rb +++ b/lib/fog/core/attributes.rb @@ -152,8 +152,25 @@ module Fog self end + # Returns true if a remote resource has been assigned an + # identity and we can assume it has been persisted. + # + # @return [Boolean] + def persisted? + !!identity + end + + # Returns true if a remote resource has not been assigned an + # identity. + # + # This was added for a ActiveRecord like feel but has been + # outdated by ActiveModel API using {#persisted?} + # + # @deprecated Use inverted form of {#persisted?} + # @return [Boolean] def new_record? - !identity + Fog::Logger.deprecation("#new_record? is deprecated, use !persisted? instead [light_black](#{caller.first})[/]") + !persisted? end # check that the attributes specified in args exist and is not nil