diff options
Diffstat (limited to 'activeresource/lib/active_resource/base.rb')
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 12 |
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 |