Class: Spider::Model::MapperTask
- Defined in:
- lib/spiderfw/model/mappers/mapper.rb
Overview
The MapperTask is used by the UnitOfWork. It represents an action that needs to be done, and allows to specify dependences between tasks
Instance Attribute Summary collapse
-
#action ⇒ Symbol
readonly
The task’s action.
-
#dependencies ⇒ Array
readonly
Array of MapperTasks this one depends on.
-
#object ⇒ BaseModel
readonly
The task’s subject.
-
#params ⇒ Hash
readonly
Params for the task.
Instance Method Summary collapse
-
#<<(task) ⇒ void
Addes a dependency to the Task.
-
#===(task) ⇒ bool
Same as #eql?.
-
#eql?(task) ⇒ bool
True if the other task has the same object, action and params, false otherwise.
-
#execute ⇒ void
Makes the objects’ mapper run the task.
-
#hash ⇒ String
Hash for keying.
-
#initialize(object, action, params = {}) ⇒ MapperTask
constructor
A new instance of MapperTask.
-
#inspect ⇒ String
A textual representation of the Task.
Constructor Details
#initialize(object, action, params = {}) ⇒ MapperTask
Returns a new instance of MapperTask.
1347 1348 1349 1350 1351 1352 |
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1347 def initialize(object, action, params={}) @object = object @action = action @params = params @dependencies = [] end |
Instance Attribute Details
#action ⇒ Symbol (readonly)
Returns The task’s action.
1340 1341 1342 |
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1340 def action @action end |
#dependencies ⇒ Array (readonly)
Returns Array of MapperTasks this one depends on.
1336 1337 1338 |
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1336 def dependencies @dependencies end |
#object ⇒ BaseModel (readonly)
Returns The task’s subject.
1338 1339 1340 |
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1338 def object @object end |
#params ⇒ Hash (readonly)
Returns Params for the task.
1342 1343 1344 |
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1342 def params @params end |
Instance Method Details
#<<(task) ⇒ void
This method returns an undefined value.
Addes a dependency to the Task
1357 1358 1359 |
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1357 def <<(task) @dependencies << task end |
#===(task) ⇒ bool
Returns Same as #eql?.
1386 1387 1388 |
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1386 def ===(task) return eql?(task) end |
#eql?(task) ⇒ bool
Returns True if the other task has the same object, action and params, false otherwise.
1371 1372 1373 1374 1375 1376 1377 1378 |
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1371 def eql?(task) return false unless task.class == self.class return false unless (task.object == self.object && task.action == self.action) @params.each do |k, v| return false unless task.params[k] == v end return true end |
#execute ⇒ void
This method returns an undefined value.
Makes the objects’ mapper run the task
1363 1364 1365 1366 1367 1368 |
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1363 def execute debug_str = "Executing #{@action} on #{@object.class}(#{@object.primary_keys.inspect})" debug_str += " (#{@params.inspect})" unless @params.empty? Spider::Logger.debug debug_str @object.mapper.execute_action(@action, @object, @params) end |
#hash ⇒ String
Returns Hash for keying.
1381 1382 1383 |
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1381 def hash return @object.hash + @action.hash end |
#inspect ⇒ String
Returns A textual representation of the Task.
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 |
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1395 def inspect if (@action && @object) str = "#{@action} on #{@object}##{@object.object_id} (#{object.class})" str += " (#{@params.inspect})" unless @params.empty? if (@dependencies.length > 0) str += " (dependencies: #{@dependencies.map{ |dep| "#{dep.action} on #{dep.object.class} #{dep.object}##{dep.object.object_id}"}.join(', ')})" # str += "-dependencies:\n" # @dependencies.each do |dep| # str += "---#{dep.action} on #{dep.object}\n" # end end else str = "Root Task" end return str end |