From 9848197e9e0830c569ae2addcd404c59c0a53180 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Mon, 7 Feb 2011 10:07:34 +0100 Subject: add Dataset.exist as find loads all data --- lib/dataset.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/dataset.rb') diff --git a/lib/dataset.rb b/lib/dataset.rb index a4716dc..02b89cb 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -56,6 +56,19 @@ module OpenTox dataset.load_all(subjectid) dataset end + + # replaces find as exist check, takes not as long, does NOT raise an un-authorized exception + # @param [String] uri Dataset URI + # @return [Boolean] true if dataset exists and user has get rights, false else + def self.exist?(uri, subjectid=nil) + return false unless uri + dataset = Dataset.new(uri, subjectid) + begin + dataset.load_metadata( subjectid ).size > 0 + rescue + false + end + end # Get all datasets from a service # @param [optional,String] uri URI of the dataset service, defaults to service specified in configuration -- cgit v1.2.3