Class: Arango::Task
- Inherits:
-
Object
- Object
- Arango::Task
- Includes:
- Database_Return, Helper_Error, Helper_Return
- Defined in:
- lib/Task.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
DEFINE ===.
-
#cache_name ⇒ Object
readonly
DEFINE ===.
-
#command ⇒ Object
Returns the value of attribute command.
-
#created ⇒ Object
Returns the value of attribute created.
-
#database ⇒ Object
readonly
DEFINE ===.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#params ⇒ Object
Returns the value of attribute params.
-
#period ⇒ Object
Returns the value of attribute period.
-
#server ⇒ Object
readonly
DEFINE ===.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #create(command: @command, period: @period, offset: @offset, params: @params) ⇒ Object
- #destroy ⇒ Object
-
#initialize(id: nil, name: nil, type: nil, period: nil, command: nil, params: nil, created: nil, body: {}, database:, cache_name: nil) ⇒ Task
constructor
A new instance of Task.
-
#retrieve ⇒ Object
RETRIEVE.
-
#to_h ⇒ Object
TO HASH ===.
- #update(command: @command, period: @period, offset: @offset, params: @params) ⇒ Object
Methods included from Database_Return
Methods included from Helper_Return
#return_delete, #return_directly?, #return_element
Methods included from Helper_Error
#satisfy_category?, #satisfy_class?, #warning_deprecated
Constructor Details
#initialize(id: nil, name: nil, type: nil, period: nil, command: nil, params: nil, created: nil, body: {}, database:, cache_name: nil) ⇒ Task
Returns a new instance of Task.
28 29 30 31 32 33 34 35 36 37 38 39 |
# 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 |
Instance Attribute Details
#body ⇒ Object
DEFINE ===
43 44 45 |
# File 'lib/Task.rb', line 43 def body @body end |
#cache_name ⇒ Object (readonly)
DEFINE ===
43 44 45 |
# File 'lib/Task.rb', line 43 def cache_name @cache_name end |
#command ⇒ Object
Returns the value of attribute command.
44 45 46 |
# File 'lib/Task.rb', line 44 def command @command end |
#created ⇒ Object
Returns the value of attribute created.
44 45 46 |
# File 'lib/Task.rb', line 44 def created @created end |
#database ⇒ Object (readonly)
DEFINE ===
43 44 45 |
# File 'lib/Task.rb', line 43 def database @database end |
#id ⇒ Object
Returns the value of attribute id.
44 45 46 |
# File 'lib/Task.rb', line 44 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
44 45 46 |
# File 'lib/Task.rb', line 44 def name @name end |
#offset ⇒ Object
Returns the value of attribute offset.
44 45 46 |
# File 'lib/Task.rb', line 44 def offset @offset end |
#params ⇒ Object
Returns the value of attribute params.
44 45 46 |
# File 'lib/Task.rb', line 44 def params @params end |
#period ⇒ Object
Returns the value of attribute period.
44 45 46 |
# File 'lib/Task.rb', line 44 def period @period end |
#server ⇒ Object (readonly)
DEFINE ===
43 44 45 |
# File 'lib/Task.rb', line 43 def server @server end |
#type ⇒ Object
Returns the value of attribute type.
44 45 46 |
# File 'lib/Task.rb', line 44 def type @type end |
Class Method Details
.new(*args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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 |
Instance Method Details
#create(command: @command, period: @period, offset: @offset, params: @params) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# 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 ⇒ Object
115 116 117 118 |
# File 'lib/Task.rb', line 115 def destroy result = @server.request("DELETE", "_api/tasks/#{@id}") return return_directly?(result) ? result : true end |
#retrieve ⇒ Object
RETRIEVE
82 83 84 85 |
# File 'lib/Task.rb', line 82 def retrieve result = @database.request("GET", "_api/tasks/#{@id}") return return_element(result) end |
#to_h ⇒ Object
TO HASH ===
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/Task.rb', line 66 def to_h { "id": @id, "name": @name, "type": @type, "period": @period, "command": @command, "params": @params, "created": @created, "cache_name": @cache_name, "database": @database.name }.delete_if{|k,v| v.nil?} end |
#update(command: @command, period: @period, offset: @offset, params: @params) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# 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 |