class Arango::Task
Attributes
command[RW]
created[RW]
id[RW]
name[RW]
offset[RW]
params[RW]
period[RW]
type[RW]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/Task.rb, line 9 def self.new(*args) hash = args[0] super unless hash.is_a?(Hash) database = hash[:database] if database.is_a?(Arango::Database) && database.server.active_cache && !hash[:id].nil? cache_name = "#{database.name}/#{hash[:id]}" cached = database.server.cache.cache.dig(:task, cache_name) if cached.nil? hash[:cache_name] = cache_name return super else body = hash[:body] || {} [:name, :type, :period, :command, :params, :created].each{|k| body[k] ||= hash[k]} cached.assign_attributes(body) end end super end
new(id: nil, name: nil, type: nil, period: nil, command: nil, params: nil, created: nil, body: {}, database:, cache_name: nil)
click to toggle source
# File lib/Task.rb, line 28 def initialize(id: nil, name: nil, type: nil, period: nil, command: nil, params: nil, created: nil, body: {}, database:, cache_name: nil) assign_database(database) unless cache_name.nil? @cache_name = cache_name @server.cache.save(:task, cache_name, self) end [:id, :name, :type, :period, :command, :params, :created].each do |k| body[k] ||= binding.local_variable_get(k) end assign_attributes(body) end
Public Instance Methods
body=(result)
click to toggle source
# File lib/Task.rb, line 47 def body=(result) @body = result @id = result[:id] || @id @name = result[:name] || @name @type = result[:type] || @type @period = result[:period] || @period @command = result[:command] || @command @params = result[:params] || @params @offset = result[:offset] || @offset @created = result[:created] || @created if @server.active_cache && @cache_name.nil? @cache_name = "#{@database.name}/#{@id}" @server.cache.save(:task, @cache_name, self) end end
Also aliased as: assign_attributes
create(command: @command, period: @period, offset: @offset, params: @params)
click to toggle source
# File lib/Task.rb, line 87 def create(command: @command, period: @period, offset: @offset, params: @params) body = { "id": @id, "name": @name, "command": command, "period": period, "offset": offset, "params": params, "database": @database.name } result = @database.request("POST", "_api/tasks", body: body) return return_element(result) end
destroy()
click to toggle source
# File lib/Task.rb, line 115 def destroy result = @server.request("DELETE", "_api/tasks/#{@id}") return return_directly?(result) ? result : true end
retrieve()
click to toggle source
to_h()
click to toggle source
update(command: @command, period: @period, offset: @offset, params: @params)
click to toggle source
# File lib/Task.rb, line 101 def update(command: @command, period: @period, offset: @offset, params: @params) body = { "id": @id, "name": @name, "command": command, "period": period, "offset": offset, "params": params } result = @database.request("PUT", "_api/tasks/#{@id}", body: body) return return_element(result) end