mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[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
This commit is contained in:
parent
e2fbe1fc26
commit
bc09d7bbee
1 changed files with 18 additions and 1 deletions
|
@ -152,8 +152,25 @@ module Fog
|
||||||
self
|
self
|
||||||
end
|
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?
|
def new_record?
|
||||||
!identity
|
Fog::Logger.deprecation("#new_record? is deprecated, use !persisted? instead [light_black](#{caller.first})[/]")
|
||||||
|
!persisted?
|
||||||
end
|
end
|
||||||
|
|
||||||
# check that the attributes specified in args exist and is not nil
|
# check that the attributes specified in args exist and is not nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue