aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/lib/active_resource/base.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-01-12 07:20:05 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-01-12 07:20:05 +0000
commit2bb33bbd590b1217f0a6576de34105ab1db3510c (patch)
tree4133c16561bfdb8f9c99b7e6f15b6b074826515e /activeresource/lib/active_resource/base.rb
parentfa619b051b5e12c6b1e8b91a32d6738edafcc3af (diff)
downloadrails-2bb33bbd590b1217f0a6576de34105ab1db3510c.tar.gz
rails-2bb33bbd590b1217f0a6576de34105ab1db3510c.tar.bz2
rails-2bb33bbd590b1217f0a6576de34105ab1db3510c.zip
Base.exists?(id, options) and Base#exists? check whether the resource is found. Closes #6970.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5898 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/lib/active_resource/base.rb')
-rw-r--r--activeresource/lib/active_resource/base.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index 7f99e5cbf5..8babc18507 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -80,6 +80,13 @@ module ActiveResource
connection.delete(element_path(id))
end
+ # True if the resource is found.
+ def exists?(id, options = {})
+ id && !find_single(id, options).nil?
+ rescue ActiveResource::ResourceNotFound
+ false
+ end
+
private
def find_every(options)
collection = connection.get(collection_path(options)) || []
@@ -167,6 +174,11 @@ module ActiveResource
connection.delete(element_path)
end
+ # True if this resource is found.
+ def exists?
+ !new? && self.class.exists?(id, prefix_options)
+ end
+
def to_xml(options={})
attributes.to_xml({:root => self.class.element_name}.merge(options))
end