Class: Salticid::Task
Instance Attribute Summary collapse
-
#block ⇒ Object
A named block, runnable in some context.
-
#name(name = nil) ⇒ Object
Sets or gets the name of this task.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #dup ⇒ Object
-
#initialize(name, opts = {}) ⇒ Task
constructor
A new instance of Task.
- #inspect ⇒ Object
-
#run(context = nil, *args) ⇒ Object
Runs the task in a given context.
- #to_s ⇒ Object
- #to_string ⇒ Object
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
#block ⇒ Object
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 |
#dup ⇒ Object
14 15 16 17 18 |
# File 'lib/salticid/task.rb', line 14 def dup dup = Salticid::Task.new(@name) dup.block = @block dup end |
#inspect ⇒ Object
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_s ⇒ Object
42 43 44 |
# File 'lib/salticid/task.rb', line 42 def to_s @name.to_s end |
#to_string ⇒ Object
46 47 48 |
# File 'lib/salticid/task.rb', line 46 def to_string "Task #{self}" end |