Class: Arvados::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/arvados.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.api_exec(method, parameters = {}) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/arvados.rb', line 147

def self.api_exec(method, parameters={})
  parameters = parameters.
    merge(:api_token => ENV['ARVADOS_API_TOKEN'])
  parameters.each do |k,v|
    parameters[k] = v.to_json if v.is_a? Array or v.is_a? Hash
  end
  result = client.
    execute(:api_method => arvados_api.send(api_models_sym).send(method),
            :authenticated => false,
            :parameters => parameters)
  resp = JSON.parse result.body, :symbolize_names => true
  if resp[:errors]
    raise Arvados::TransactionFailedError.new(resp[:errors])
  end
  resp
end

.arvados_apiObject



135
136
137
# File 'lib/arvados.rb', line 135

def self.arvados_api
  arvados.arvados_api
end

.clientObject



138
139
140
# File 'lib/arvados.rb', line 138

def self.client
  arvados.client
end

.debuglog(*args) ⇒ Object



141
142
143
# File 'lib/arvados.rb', line 141

def self.debuglog(*args)
  arvados.class.debuglog *args
end

Instance Method Details

#[](x) ⇒ Object



168
169
170
171
172
173
174
175
176
# File 'lib/arvados.rb', line 168

def [](x)
  if @attributes[x].is_a? Hash or @attributes[x].is_a? Array
    # We won't be notified via []= if these change, so we'll just
    # assume they are going to get changed, and submit them if
    # save() is called.
    @attributes_to_update[x] = @attributes[x]
  end
  @attributes[x]
end

#[]=(x, y) ⇒ Object



164
165
166
167
# File 'lib/arvados.rb', line 164

def []=(x,y)
  @attributes_to_update[x] = y
  @attributes[x] = y
end

#debuglog(*args) ⇒ Object



144
145
146
# File 'lib/arvados.rb', line 144

def debuglog(*args)
  self.class.arvados.class.debuglog *args
end

#saveObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/arvados.rb', line 177

def save
  @attributes_to_update.keys.each do |k|
    @attributes_to_update[k] = @attributes[k]
  end
  j = self.class.api_exec :update, {
    :uuid => @attributes[:uuid],
    self.class.api_model_sym => @attributes_to_update.to_json
  }
  unless j.is_a? Hash and j[:uuid]
    debuglog "Failed to save #{self.to_s}: #{j[:errors] rescue nil}", 0
    nil
  else
    @attributes_to_update = {}
    @attributes = j
  end
end