Class: Ke::Job
- Inherits:
-
Object
- Object
- Ke::Job
- Defined in:
- lib/ke/job.rb
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#reporter ⇒ Object
readonly
Returns the value of attribute reporter.
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Instance Method Summary collapse
-
#initialize(task, reporter, opts = {}) ⇒ Job
constructor
A new instance of Job.
- #run ⇒ Object
- #tick ⇒ Object
Constructor Details
#initialize(task, reporter, opts = {}) ⇒ Job
Returns a new instance of Job.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ke/job.rb', line 5 def initialize(task, reporter, opts = {}) @task = task @reporter = reporter @opts = opts @opts[:report_every] ||= if @task.respond_to?(:total_ticks) [1, [@task.total_ticks / 10, 100].min].max else 1 end end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
3 4 5 |
# File 'lib/ke/job.rb', line 3 def opts @opts end |
#reporter ⇒ Object (readonly)
Returns the value of attribute reporter.
3 4 5 |
# File 'lib/ke/job.rb', line 3 def reporter @reporter end |
#task ⇒ Object (readonly)
Returns the value of attribute task.
3 4 5 |
# File 'lib/ke/job.rb', line 3 def task @task end |
Instance Method Details
#run ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/ke/job.rb', line 23 def run task.start reporter.print_start return_val = yield(self) task.complete reporter.print_complete return_val end |
#tick ⇒ Object
17 18 19 20 21 |
# File 'lib/ke/job.rb', line 17 def tick task.tick reporter.print_tick if task.tick_count % opts[:report_every] == 0 yield end |