Class: Salticid::Task

Inherits:
Object show all
Defined in:
lib/salticid/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts = {}) ⇒ Task

Returns a new instance of Task.



5
6
7
# File 'lib/salticid/task.rb', line 5

def initialize(name, opts = {})
  @name = name.to_s
end

Instance Attribute Details

#blockObject

A named block, runnable in some context



3
4
5
# File 'lib/salticid/task.rb', line 3

def block
  @block
end

#name(name = nil) ⇒ Object

Sets or gets the name of this task.



3
4
5
# File 'lib/salticid/task.rb', line 3

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



9
10
11
12
# File 'lib/salticid/task.rb', line 9

def ==(other)
  self.name == other.name and
  self.block == other.block
end

#dupObject



14
15
16
17
18
# File 'lib/salticid/task.rb', line 14

def dup
  dup = Salticid::Task.new(@name)
  dup.block = @block 
  dup
end

#inspectObject



20
21
22
# File 'lib/salticid/task.rb', line 20

def inspect
  "#<Task #{@name}>"
end

#run(context = nil, *args) ⇒ Object

Runs the task in a given context



34
35
36
37
38
39
40
# File 'lib/salticid/task.rb', line 34

def run(context = nil, *args)
  if context
    context.instance_exec(*args, &@block)
  else
    @block.call(*args)
  end
end

#to_sObject



42
43
44
# File 'lib/salticid/task.rb', line 42

def to_s
  @name.to_s
end

#to_stringObject



46
47
48
# File 'lib/salticid/task.rb', line 46

def to_string
  "Task #{self}"
end