Class: ClockworkMocks::Scheduler
- Inherits:
-
Object
- Object
- ClockworkMocks::Scheduler
- Defined in:
- lib/clockwork_mocks/scheduler.rb
Instance Attribute Summary collapse
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Class Method Summary collapse
Instance Method Summary collapse
- #every(interval, name, hash = {}, &block) ⇒ Object
-
#initialize ⇒ Scheduler
constructor
A new instance of Scheduler.
- #reset! ⇒ Object
- #work ⇒ Object
Constructor Details
#initialize ⇒ Scheduler
Returns a new instance of Scheduler.
7 8 9 |
# File 'lib/clockwork_mocks/scheduler.rb', line 7 def initialize() @tasks = [] end |
Instance Attribute Details
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
5 6 7 |
# File 'lib/clockwork_mocks/scheduler.rb', line 5 def tasks @tasks end |
Class Method Details
.init_rspec(allow, receive, clock_file = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/clockwork_mocks/scheduler.rb', line 11 def self.init_rspec(allow, receive, clock_file = nil) scheduler = Scheduler.new allow.call(Clockwork).to receive.call(:every) do |interval, name, hash, &block| scheduler.every interval, name, hash, &block end if block_given? yield else unless clock_file rails = Object.const_get('Rails') clock_file = "#{rails.root}/clock.rb" if rails end load clock_file if clock_file end scheduler end |
Instance Method Details
#every(interval, name, hash = {}, &block) ⇒ Object
46 47 48 |
# File 'lib/clockwork_mocks/scheduler.rb', line 46 def every(interval, name, hash = {}, &block) @tasks.push ClockworkTask.new(interval, name, hash, block) end |
#reset! ⇒ Object
42 43 44 |
# File 'lib/clockwork_mocks/scheduler.rb', line 42 def reset! @tasks.each(&:reset!) end |
#work ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/clockwork_mocks/scheduler.rb', line 32 def work loop do t = @tasks.min_by(&:due) break if t.nil? || t.due > Time.now t.perform end end |