From ae55440e99529c18367f93e3f6e6b40816767f44 Mon Sep 17 00:00:00 2001 From: gebele Date: Tue, 7 May 2013 17:06:27 +0200 Subject: exchanged accessible rule with HEAD request --- lib/overwrite.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/overwrite.rb b/lib/overwrite.rb index d1f3d9d..10a68e7 100644 --- a/lib/overwrite.rb +++ b/lib/overwrite.rb @@ -91,13 +91,15 @@ module URI def self.accessible?(uri, subjectid=nil) parsed_uri = URI.parse(uri + (subjectid ? "?subjectid=#{CGI.escape subjectid}" : "")) http_code = URI.task?(uri) ? 600 : 400 - unless URI.ssl? uri - Net::HTTP.get_response(parsed_uri).code.to_i < http_code + unless (URI.ssl? uri) == true + http = Net::HTTP.new(parsed_uri.host, parsed_uri.port) + request = Net::HTTP::Head.new(parsed_uri.request_uri) + http.request(request).code.to_i < http_code else http = Net::HTTP.new(parsed_uri.host, parsed_uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE - request = Net::HTTP::Get.new(parsed_uri.request_uri) + request = Net::HTTP::Head.new(parsed_uri.request_uri) http.request(request).code.to_i < http_code end rescue -- cgit v1.2.3 From 508cff7269bff31ad3b8f319125522762fe54372 Mon Sep 17 00:00:00 2001 From: gebele Date: Wed, 8 May 2013 10:22:59 +0200 Subject: removed head request from accessible? --- lib/overwrite.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/overwrite.rb b/lib/overwrite.rb index 10a68e7..b758450 100644 --- a/lib/overwrite.rb +++ b/lib/overwrite.rb @@ -93,13 +93,13 @@ module URI http_code = URI.task?(uri) ? 600 : 400 unless (URI.ssl? uri) == true http = Net::HTTP.new(parsed_uri.host, parsed_uri.port) - request = Net::HTTP::Head.new(parsed_uri.request_uri) + request = Net::HTTP::Get.new(parsed_uri.request_uri) http.request(request).code.to_i < http_code else http = Net::HTTP.new(parsed_uri.host, parsed_uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE - request = Net::HTTP::Head.new(parsed_uri.request_uri) + request = Net::HTTP::Get.new(parsed_uri.request_uri) http.request(request).code.to_i < http_code end rescue -- cgit v1.2.3 From 7fe4a8863cd0876e4b3c932da17b11454b7c2523 Mon Sep 17 00:00:00 2001 From: gebele Date: Fri, 10 May 2013 17:12:32 +0200 Subject: changed rdf reader/writer --- lib/error.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/error.rb b/lib/error.rb index eb72144..85ce35d 100644 --- a/lib/error.rb +++ b/lib/error.rb @@ -41,7 +41,7 @@ module OpenToxError def to_turtle # redefine to use prefixes (not supported by RDF::Writer) prefixes = {:rdf => "http://www.w3.org/1999/02/22-rdf-syntax-ns#"} ['OT', 'DC', 'XSD', 'OLO'].each{|p| prefixes[p.downcase.to_sym] = eval("RDF::#{p}.to_s") } - RDF::N3::Writer.for(:turtle).buffer(:prefixes => prefixes) do |writer| + RDF::Turtle::Writer.for(:turtle).buffer(:prefixes => prefixes) do |writer| @rdf.each{|statement| writer << statement} if @rdf end end -- cgit v1.2.3 From e2399fc85379066abf0b72803402fc440b61629c Mon Sep 17 00:00:00 2001 From: gebele Date: Fri, 10 May 2013 17:14:08 +0200 Subject: changed rdf reader/writer --- lib/opentox.rb | 2 +- lib/task.rb | 2 +- opentox-client.gemspec | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/opentox.rb b/lib/opentox.rb index 78a6923..292eb6f 100644 --- a/lib/opentox.rb +++ b/lib/opentox.rb @@ -167,7 +167,7 @@ module OpenTox prefixes = {:rdf => "http://www.w3.org/1999/02/22-rdf-syntax-ns#"} ['OT', 'DC', 'XSD', 'OLO'].each{|p| prefixes[p.downcase.to_sym] = eval("RDF::#{p}.to_s") } create_rdf - RDF::N3::Writer.for(:turtle).buffer(:prefixes => prefixes) do |writer| + RDF::Turtle::Writer.for(:turtle).buffer(:prefixes => prefixes) do |writer| @rdf.each{|statement| writer << statement} end end diff --git a/lib/task.rb b/lib/task.rb index 944f20c..3cc05c0 100644 --- a/lib/task.rb +++ b/lib/task.rb @@ -46,7 +46,7 @@ module OpenTox @rdf << [subject, RDF::OT.errorCode, $!.class.to_s] @rdf << [subject, RDF::OT.errorCause, $!.backtrace[0..cut_index].join("\n")] prefixes = {:rdf => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", :ot => RDF::OT.to_s} - turtle = RDF::N3::Writer.for(:turtle).buffer(:prefixes => prefixes) do |writer| + turtle = RDF::Turtle::Writer.for(:turtle).buffer(:prefixes => prefixes) do |writer| @rdf.each{|statement| writer << statement} end $logger.error turtle diff --git a/opentox-client.gemspec b/opentox-client.gemspec index f9d333a..dd4d06c 100644 --- a/opentox-client.gemspec +++ b/opentox-client.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency "rest-client" s.add_runtime_dependency "rdf" s.add_runtime_dependency "rdf-raptor" - s.add_runtime_dependency 'rdf-n3' + s.add_runtime_dependency 'rdf-turtle' s.add_runtime_dependency "open4" # external requirements -- cgit v1.2.3 From fda7902689d879e593406d3a710f6d6a8c322db7 Mon Sep 17 00:00:00 2001 From: gebele Date: Fri, 10 May 2013 17:14:56 +0200 Subject: changed rdf reader/writer --- lib/opentox-client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/opentox-client.rb b/lib/opentox-client.rb index 16b8552..02724c2 100644 --- a/lib/opentox-client.rb +++ b/lib/opentox-client.rb @@ -2,7 +2,7 @@ require 'rubygems' require "bundler/setup" require 'rdf' require 'rdf/raptor' -require 'rdf/n3' +require 'rdf/turtle' require "rest-client" require 'uri' require 'yaml' -- cgit v1.2.3 From 11ce0ec19003d177920891e815a2a16f2b53f347 Mon Sep 17 00:00:00 2001 From: gebele Date: Fri, 10 May 2013 17:17:22 +0200 Subject: changed accessible rule to HEAD request --- lib/overwrite.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/overwrite.rb b/lib/overwrite.rb index b758450..10a68e7 100644 --- a/lib/overwrite.rb +++ b/lib/overwrite.rb @@ -93,13 +93,13 @@ module URI http_code = URI.task?(uri) ? 600 : 400 unless (URI.ssl? uri) == true http = Net::HTTP.new(parsed_uri.host, parsed_uri.port) - request = Net::HTTP::Get.new(parsed_uri.request_uri) + request = Net::HTTP::Head.new(parsed_uri.request_uri) http.request(request).code.to_i < http_code else http = Net::HTTP.new(parsed_uri.host, parsed_uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE - request = Net::HTTP::Get.new(parsed_uri.request_uri) + request = Net::HTTP::Head.new(parsed_uri.request_uri) http.request(request).code.to_i < http_code end rescue -- cgit v1.2.3 From 7def60bb82474c5e12bbc0362476752524e25d53 Mon Sep 17 00:00:00 2001 From: gebele Date: Wed, 15 May 2013 13:43:20 +0200 Subject: require openbabel --- lib/compound.rb | 1 + opentox-client.gemspec | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/compound.rb b/lib/compound.rb index 5d77dec..294aa90 100644 --- a/lib/compound.rb +++ b/lib/compound.rb @@ -1,3 +1,4 @@ +require "openbabel" CACTUS_URI="http://cactus.nci.nih.gov/chemical/structure/" module OpenTox diff --git a/opentox-client.gemspec b/opentox-client.gemspec index dd4d06c..872a985 100644 --- a/opentox-client.gemspec +++ b/opentox-client.gemspec @@ -25,6 +25,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency "rdf-raptor" s.add_runtime_dependency 'rdf-turtle' s.add_runtime_dependency "open4" + s.add_runtime_dependency "openbabel" # external requirements ["libraptor-dev"].each{|r| s.requirements << r} -- cgit v1.2.3 From 91fb2899d89311ad5f52c1a5aded3a833ea9fb1d Mon Sep 17 00:00:00 2001 From: gebele Date: Wed, 15 May 2013 20:03:00 +0200 Subject: check rdf befor build --- lib/opentox.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/opentox.rb b/lib/opentox.rb index 292eb6f..211fc7b 100644 --- a/lib/opentox.rb +++ b/lib/opentox.rb @@ -129,7 +129,7 @@ module OpenTox end def create_rdf - @rdf = RDF::Graph.new + @rdf = RDF::Graph.new if @rdf.empty? or URI.task?(@uri) @metadata[RDF.type] ||= eval("RDF::OT."+self.class.to_s.split('::').last) @metadata[RDF::DC.date] ||= DateTime.now @metadata.each do |predicate,values| -- cgit v1.2.3 From 3922d47b9695014fddde72aacfe3c6f226491902 Mon Sep 17 00:00:00 2001 From: davor Date: Tue, 21 May 2013 17:43:53 +0200 Subject: Added detailed filter for NominalFeature. --- lib/dataset.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/dataset.rb b/lib/dataset.rb index f261641..8d5f5d1 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -64,7 +64,15 @@ module OpenTox # TODO: fallbacks for external and unordered datasets features.each_with_index do |feature,i| if feature[RDF.type].include? RDF::OT.NumericFeature - @data_entries.each { |row| row[i] = row[i].to_f if row[i] } + if feature[RDF.type].include? RDF::OT.NominalFeature + if feature[RDF.type].include? RDF::OT.StringFeature + @data_entries.each { |row| row[i] = row[i].to_s if row[i] } + else + @data_entries.each { |row| row[i] = row[i] if row[i] } + end + else + @data_entries.each { |row| row[i] = row[i].to_f if row[i] } + end end end end -- cgit v1.2.3 From ccafc5212c633310ad21d043236cc5a440827bf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20G=C3=BCtlein?= Date: Tue, 28 May 2013 11:23:18 +0200 Subject: added comments to overwrite --- lib/overwrite.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/overwrite.rb b/lib/overwrite.rb index 10a68e7..52b8a9f 100644 --- a/lib/overwrite.rb +++ b/lib/overwrite.rb @@ -12,13 +12,14 @@ class Object end module Enumerable + # @return [Array] only the duplicates of an enumerable def duplicates inject({}) {|h,v| h[v]=h[v].to_i+1; h}.reject{|k,v| v==1}.keys end end class String - + # @return [String] converts camel-case to underscore-case (OpenTox::SuperModel -> open_tox/super_model) def underscore self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). @@ -88,6 +89,7 @@ module URI URI.parse(uri).instance_of? URI::HTTPS end + # @return [Boolean] checks if resource exists by making a HEAD-request def self.accessible?(uri, subjectid=nil) parsed_uri = URI.parse(uri + (subjectid ? "?subjectid=#{CGI.escape subjectid}" : "")) http_code = URI.task?(uri) ? 600 : 400 @@ -116,6 +118,7 @@ module URI end class File + # @return [String] mime_type including charset using linux cmd command def mime_type `file -ib #{self.path}`.chomp end @@ -138,6 +141,7 @@ module Kernel internal_server_error $!.message end + # @return [String] uri of task result, if task fails, an error according to task is raised def wait_for_task uri if URI.task?(uri) t = OpenTox::Task.new uri @@ -165,7 +169,7 @@ end class Array - # Sum of an array for Arrays + # Sum up the size of single arrays in an array of arrays # @param [Array] Array of arrays # @return [Integer] Sum of size of array elements def sum_size -- cgit v1.2.3 From 68d1f71f268fde0a36d0e530385c8025dcb5d132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20G=C3=BCtlein?= Date: Tue, 28 May 2013 12:28:29 +0300 Subject: add comment --- lib/otlogger.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/otlogger.rb b/lib/otlogger.rb index 57b8170..0f0caa4 100644 --- a/lib/otlogger.rb +++ b/lib/otlogger.rb @@ -1,3 +1,5 @@ + +# extend logger to add current source file, line-number and source location where the log command is called class OTLogger < Logger def pwd -- cgit v1.2.3 From 39b094bf106b35fb8fa41fd387bbb43bfe285672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20G=C3=BCtlein?= Date: Tue, 28 May 2013 12:37:52 +0300 Subject: added short comment --- lib/rest-client-wrapper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/rest-client-wrapper.rb b/lib/rest-client-wrapper.rb index 38219c1..f3e6300 100644 --- a/lib/rest-client-wrapper.rb +++ b/lib/rest-client-wrapper.rb @@ -57,6 +57,7 @@ module OpenTox end end + #@return [Array] of hashes with error code, method and class def self.known_errors errors = [] RestClient::STATUSES.each do |code,k| -- cgit v1.2.3 From 81b0d1f738ccb61f25ffde4162ceead49180f0d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20G=C3=BCtlein?= Date: Tue, 28 May 2013 12:44:43 +0300 Subject: updating comments --- lib/algorithm.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/algorithm.rb b/lib/algorithm.rb index 455e9ad..530296a 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -5,7 +5,7 @@ module OpenTox # Execute algorithm with parameters, please consult the OpenTox API and the webservice documentation for acceptable parameters # @param [optional,Hash] params Algorithm parameters - # @param [optional,OpenTox::Task] waiting_task (can be a OpenTox::Subtask as well), progress is updated accordingly + # @param [optional,Boolean] set to true if method should wait for task result # @return [String] URI of new resource (dataset, model, ...) def run params=nil, wait=true uri = RestClientWrapper.post @uri, params, { :content_type => "text/uri-list", :subjectid => @subjectid} -- cgit v1.2.3 From 2de472ba1c066aec3d4416b21a68b0b480e9aeb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20G=C3=BCtlein?= Date: Tue, 28 May 2013 12:59:31 +0300 Subject: update comments --- lib/authorization.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/authorization.rb b/lib/authorization.rb index 5a846c9..4d49b40 100644 --- a/lib/authorization.rb +++ b/lib/authorization.rb @@ -1,10 +1,10 @@ module OpenTox AA = $aa[:uri] if defined? $aa - AA ||= "https://opensso.in-silico.ch" #if not set in .opentox/conf/[application]/[test].rb + AA ||= "https://opensso.in-silico.ch" #if not set in .opentox/conf/[SERVICE].rb #Module for Authorization and Authentication #@example Authentication # require "opentox-client" - # OpenTox::Authorization::AA = "https://opensso.in-silico.ch" #if not set in .opentox/conf/[environment].yaml + # OpenTox::Authorization::AA = "https://opensso.in-silico.ch" #if not set in .opentox/conf/[SERVICE].rb # subjectid = OpenTox::Authorization.authenticate("username", "password") #@see http://www.opentox.org/dev/apis/api-1.2/AA OpenTox A&A API 1.2 specification @@ -337,10 +337,11 @@ module OpenTox end private + # @return [Boolean] checks if uri-method pair is included in :free_uri def self.free_uri?(uri, request_method) if $aa[:free_uris] $aa[:free_uris].each do |request_methods,uris| - if request_methods and uris and request_methods.include?(request_method.to_s) + if request_methods and uris and request_methods.include?(request_method.to_sym) uris.each do |u| return true if u.match uri end @@ -350,6 +351,7 @@ module OpenTox return false end + # @return [Boolean] checks if uri-method pair is included in :authorize_exceptions def self.authorize_exception?(uri, request_method) if $aa[:authorize_exceptions] $aa[:authorize_exceptions].each do |request_methods,uris| -- cgit v1.2.3 From 0df97a547ad623cff5d714076addbaa3cc73c53b Mon Sep 17 00:00:00 2001 From: davor Date: Tue, 28 May 2013 12:15:36 +0200 Subject: Replacing tab with two spaces. --- lib/compound.rb | 126 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/lib/compound.rb b/lib/compound.rb index 294aa90..2eccdcd 100644 --- a/lib/compound.rb +++ b/lib/compound.rb @@ -4,7 +4,7 @@ CACTUS_URI="http://cactus.nci.nih.gov/chemical/structure/" module OpenTox # Ruby wrapper for OpenTox Compound Webservices (http://opentox.org/dev/apis/api-1.2/structure). - class Compound + class Compound # Create a compound from smiles string # @example @@ -40,57 +40,57 @@ module OpenTox Compound.new RestClientWrapper.post(service_uri, @inchi, {:content_type => 'chemical/x-inchi', :subjectid => subjectid}) end - # Get InChI + # Get InChI # @return [String] InChI string - def inchi + def inchi @inchi ||= RestClientWrapper.get(@uri,{},{:accept => 'chemical/x-inchi'}).chomp - end + end - # Get InChIKey + # Get InChIKey # @return [String] InChI string - def inchikey + def inchikey @inchikey ||= RestClientWrapper.get(@uri,{},{:accept => 'chemical/x-inchikey'}).chomp - end + end - # Get (canonical) smiles + # Get (canonical) smiles # @return [String] Smiles string - def smiles + def smiles @smiles ||= RestClientWrapper.get(@uri,{},{:accept => 'chemical/x-daylight-smiles'}).chomp - end + end # Get sdf # @return [String] SDF string - def sdf + def sdf RestClientWrapper.get(@uri,{},{:accept => 'chemical/x-mdl-sdfile'}).chomp - end + end # Get gif image # @return [image/gif] Image data - def gif + def gif RestClientWrapper.get File.join(CACTUS_URI,inchi,"image") - end + end # Get png image # @example # image = compound.png # @return [image/png] Image data - def png + def png RestClientWrapper.get(File.join @uri, "image") - end + end # Get URI of compound image # @return [String] Compound image URI - def image_uri + def image_uri File.join @uri, "image" - end + end # Get all known compound names. Relies on an external service for name lookups. # @example # names = compound.names # @return [String] Compound names - def names + def names RestClientWrapper.get("#{CACTUS_URI}#{inchi}/names").split("\n") - end + end def cid pug_uri = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/" @@ -107,40 +107,40 @@ module OpenTox end =begin - # Match a smarts string + # Match a smarts string # @example # compound = OpenTox::Compound.from_name("Benzene") # compound.match?("cN") # returns false # @param [String] smarts Smarts string - def match?(smarts) - obconversion = OpenBabel::OBConversion.new - obmol = OpenBabel::OBMol.new - obconversion.set_in_format('inchi') - obconversion.read_string(obmol,@inchi) - smarts_pattern = OpenBabel::OBSmartsPattern.new - smarts_pattern.init(smarts) - smarts_pattern.match(obmol) - end - - # Match an array of smarts strings, returns array with matching smarts + def match?(smarts) + obconversion = OpenBabel::OBConversion.new + obmol = OpenBabel::OBMol.new + obconversion.set_in_format('inchi') + obconversion.read_string(obmol,@inchi) + smarts_pattern = OpenBabel::OBSmartsPattern.new + smarts_pattern.init(smarts) + smarts_pattern.match(obmol) + end + + # Match an array of smarts strings, returns array with matching smarts # @example # compound = OpenTox::Compound.from_name("Benzene") # compound.match(['cc','cN']) # returns ['cc'] # @param [Array] smarts_array Array with Smarts strings # @return [Array] Array with matching Smarts strings - def match(smarts_array) + def match(smarts_array) # avoid recreation of OpenBabel objects - obconversion = OpenBabel::OBConversion.new - obmol = OpenBabel::OBMol.new - obconversion.set_in_format('inchi') - obconversion.read_string(obmol,@inchi) - smarts_pattern = OpenBabel::OBSmartsPattern.new - smarts_array.collect do |smarts| + obconversion = OpenBabel::OBConversion.new + obmol = OpenBabel::OBMol.new + obconversion.set_in_format('inchi') + obconversion.read_string(obmol,@inchi) + smarts_pattern = OpenBabel::OBSmartsPattern.new + smarts_array.collect do |smarts| smarts_pattern.init(smarts) smarts if smarts_pattern.match(obmol) end.compact #smarts_array.collect { |s| s if match?(s)}.compact - end + end # Get URI of compound image with highlighted fragments # @@ -157,33 +157,33 @@ module OpenTox private # Convert sdf to inchi - def self.sdf2inchi(sdf) - Compound.obconversion(sdf,'sdf','inchi') - end + def self.sdf2inchi(sdf) + Compound.obconversion(sdf,'sdf','inchi') + end # Convert smiles to inchi - def self.smiles2inchi(smiles) - Compound.obconversion(smiles,'smi','inchi') - end + def self.smiles2inchi(smiles) + Compound.obconversion(smiles,'smi','inchi') + end # Convert smiles to canonical smiles - def self.smiles2cansmi(smiles) - Compound.obconversion(smiles,'smi','can') - end + def self.smiles2cansmi(smiles) + Compound.obconversion(smiles,'smi','can') + end # Convert identifier from OpenBabel input_format to OpenBabel output_format - def self.obconversion(identifier,input_format,output_format) - obconversion = OpenBabel::OBConversion.new - obmol = OpenBabel::OBMol.new - obconversion.set_in_and_out_formats input_format, output_format - obconversion.read_string obmol, identifier - case output_format - when /smi|can|inchi/ - obconversion.write_string(obmol).gsub(/\s/,'').chomp - else - obconversion.write_string(obmol) - end - end + def self.obconversion(identifier,input_format,output_format) + obconversion = OpenBabel::OBConversion.new + obmol = OpenBabel::OBMol.new + obconversion.set_in_and_out_formats input_format, output_format + obconversion.read_string obmol, identifier + case output_format + when /smi|can|inchi/ + obconversion.write_string(obmol).gsub(/\s/,'').chomp + else + obconversion.write_string(obmol) + end + end =end @@ -207,7 +207,7 @@ module OpenTox smarts_array.collect do |smarts| smarts_pattern.init(smarts) if smarts_pattern.match(obmol) - if use_hits + if use_hits hits = smarts_pattern.get_map_list smarts_hits[smarts] = hits.to_a.size else @@ -223,5 +223,5 @@ module OpenTox match_hits(smarts_array,false) end - end + end end -- cgit v1.2.3 From ef122484598a8979de915344cdeff475cff752c5 Mon Sep 17 00:00:00 2001 From: rautenberg Date: Wed, 29 May 2013 15:03:22 +0200 Subject: authorization.rb merge free_uri? and authorize_exceptions? --- lib/authorization.rb | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/lib/authorization.rb b/lib/authorization.rb index 4d49b40..469c16c 100644 --- a/lib/authorization.rb +++ b/lib/authorization.rb @@ -337,33 +337,24 @@ module OpenTox end private - # @return [Boolean] checks if uri-method pair is included in :free_uri - def self.free_uri?(uri, request_method) - if $aa[:free_uris] - $aa[:free_uris].each do |request_methods,uris| - if request_methods and uris and request_methods.include?(request_method.to_sym) - uris.each do |u| - return true if u.match uri - end - end - end - end - return false - end - - # @return [Boolean] checks if uri-method pair is included in :authorize_exceptions - def self.authorize_exception?(uri, request_method) - if $aa[:authorize_exceptions] - $aa[:authorize_exceptions].each do |request_methods,uris| - if request_methods and uris and request_methods.include?(request_method.to_sym) - uris.each do |u| - return true if u.match uri + # extend class methods + class << self + # methods: free_uri and authorize_exception + # @return [Boolean] checks if uri-method pair is included in $aa[:free_uri] or $aa[:authorize_exception] + [:free_uri, :authorize_exception].each do |method| + define_method "#{method}?".to_sym do |uri, request_method| + if $aa["#{method}s".to_sym] + $aa["#{method}s".to_sym].each do |request_methods, uris| + if request_methods and uris and request_methods.include?(request_method.to_sym) + uris.each do |u| + return true if u.match uri + end + end end end + return false end end - return false end - end end -- cgit v1.2.3