Class: Arvados
- Inherits:
-
Object
- Object
- Arvados
- Defined in:
- lib/arvados.rb
Defined Under Namespace
Classes: Model, TransactionFailedError
Constant Summary collapse
- @@debuglevel =
0
Class Attribute Summary collapse
-
.debuglevel ⇒ Object
Returns the value of attribute debuglevel.
Class Method Summary collapse
Instance Method Summary collapse
- #arvados_api ⇒ Object
- #client ⇒ Object
-
#initialize(opts = {}) ⇒ Arvados
constructor
A new instance of Arvados.
Constructor Details
#initialize(opts = {}) ⇒ Arvados
Returns a new instance of Arvados.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/arvados.rb', line 31 def initialize(opts={}) @application_version ||= 0.0 @application_name ||= File.split($0).last @arvados_api_version = opts[:api_version] || ENV['ARVADOS_API_VERSION'] || 'v1' @arvados_api_host = opts[:api_host] || ENV['ARVADOS_API_HOST'] or raise "#{$0}: no :api_host or ENV[ARVADOS_API_HOST] provided." @arvados_api_token = opts[:api_token] || ENV['ARVADOS_API_TOKEN'] or raise "#{$0}: no :api_token or ENV[ARVADOS_API_TOKEN] provided." if (opts[:api_host] ? opts[:suppress_ssl_warnings] : ENV['ARVADOS_API_HOST_INSECURE']) suppress_warnings do OpenSSL::SSL.const_set 'VERIFY_PEER', OpenSSL::SSL::VERIFY_NONE end end # Define a class and an Arvados instance method for each Arvados # resource. After this, self.job will return Arvados::Job; # self.job.new() and self.job.find() will do what you want. _arvados = self self.arvados_api.schemas.each do |classname, schema| next if classname.match /List$/ klass = Class.new(Arvados::Model) do def self.arvados @arvados end def self.api_models_sym @api_models_sym end def self.api_model_sym @api_model_sym end end # Define the resource methods (create, get, update, delete, ...) self. arvados_api. send(classname.underscore.split('/').last.pluralize.to_sym). discovered_methods. collect(&:name). each do |method_name| class << klass; self; end.class_eval do define_method method_name do |*params| self.api_exec(method_name.to_sym, *params) end end end # Give the new class access to the API klass.instance_eval do @arvados = _arvados # These should be pulled from the discovery document instead: @api_models_sym = classname.underscore.split('/').last.pluralize.to_sym @api_model_sym = classname.underscore.split('/').last.to_sym end # This might produce confusing results when using multiple # Arvados instances. Arvados.const_set classname, klass self.class.class_eval do define_method classname.underscore do klass end end end end |
Class Attribute Details
.debuglevel ⇒ Object
Returns the value of attribute debuglevel.
28 29 30 |
# File 'lib/arvados.rb', line 28 def debuglevel @debuglevel end |
Class Method Details
.debuglog(message, verbosity = 1) ⇒ Object
130 131 132 |
# File 'lib/arvados.rb', line 130 def self.debuglog(, verbosity=1) $stderr.puts "#{File.split($0).last} #{$$}: #{}" if @@debuglevel >= verbosity end |
Instance Method Details
#arvados_api ⇒ Object
126 127 128 |
# File 'lib/arvados.rb', line 126 def arvados_api @arvados_api ||= self.client.discovered_api('arvados', @arvados_api_version) end |
#client ⇒ Object
119 120 121 122 123 124 |
# File 'lib/arvados.rb', line 119 def client @client ||= Google::APIClient. new(:host => @arvados_api_host, :application_name => @application_name, :application_version => @application_version.to_s) end |