Class: Spider::Model::MapperTask

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(object, action, params = {}) ⇒ MapperTask

Returns a new instance of MapperTask.

Parameters:

  • object (BaseModel)

    The task’s subject

  • action (Symbol)
  • params (Hash) (defaults to: {})


1321
1322
1323
1324
1325
1326
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1321

def initialize(object, action, params={})
    @object = object
    @action = action
    @params = params
    @dependencies = []
end

Instance Attribute Details

#actionSymbol (readonly)

Returns The task’s action.

Returns:

  • (Symbol)

    The task’s action



1314
1315
1316
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1314

def action
  @action
end

#dependenciesArray (readonly)

Returns Array of MapperTasks this one depends on.

Returns:

  • (Array)

    Array of MapperTasks this one depends on



1310
1311
1312
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1310

def dependencies
  @dependencies
end

#objectBaseModel (readonly)

Returns The task’s subject.

Returns:



1312
1313
1314
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1312

def object
  @object
end

#paramsHash (readonly)

Returns Params for the task.

Returns:

  • (Hash)

    Params for the task



1316
1317
1318
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1316

def params
  @params
end

Instance Method Details

#<<(task) ⇒ void

This method returns an undefined value.

Addes a dependency to the Task

Parameters:



1331
1332
1333
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1331

def <<(task)
    @dependencies << task
end

#===(task) ⇒ bool

Returns Same as #eql?.

Returns:

  • (bool)

    Same as #eql?



1360
1361
1362
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1360

def ===(task)
    return eql?(task)
end

#eql?(task) ⇒ bool

Returns True if the other task has the same object, action and params, false otherwise.

Returns:

  • (bool)

    True if the other task has the same object, action and params, false otherwise



1345
1346
1347
1348
1349
1350
1351
1352
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1345

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

#executevoid

This method returns an undefined value.

Makes the objects’ mapper run the task



1337
1338
1339
1340
1341
1342
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1337

def execute
    debug_str = "Executing #{@action} on #{@object.inspect}"
    debug_str += " (#{@params.inspect})" unless @params.empty?
    Spider::Logger.debug debug_str
    @object.mapper.execute_action(@action, @object, @params)
end

#hashString

Returns Hash for keying.

Returns:

  • (String)

    Hash for keying



1355
1356
1357
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1355

def hash
    return @object.hash + @action.hash
end

#inspectString

Returns A textual representation of the Task.

Returns:

  • (String)

    A textual representation of the Task



1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
# File 'lib/spiderfw/model/mappers/mapper.rb', line 1369

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