Class: Clockworkd::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/clockworkd/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job, block, cronline) ⇒ Event

Returns a new instance of Event.



5
6
7
8
9
10
11
# File 'lib/clockworkd/event.rb', line 5

def initialize(job, block, cronline)
  @job = job
  @block = block
  @cronline = cronline
  @cron_time = CronLine.new(@cronline)
  @next_time = @cron_time.next_time
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



3
4
5
# File 'lib/clockworkd/event.rb', line 3

def block
  @block
end

#cron_timeObject

Returns the value of attribute cron_time.



3
4
5
# File 'lib/clockworkd/event.rb', line 3

def cron_time
  @cron_time
end

#cronlineObject

Returns the value of attribute cronline.



3
4
5
# File 'lib/clockworkd/event.rb', line 3

def cronline
  @cronline
end

#jobObject

Returns the value of attribute job.



3
4
5
# File 'lib/clockworkd/event.rb', line 3

def job
  @job
end

#next_timeObject

Returns the value of attribute next_time.



3
4
5
# File 'lib/clockworkd/event.rb', line 3

def next_time
  @next_time
end

Instance Method Details

#run(t) ⇒ Object



25
26
27
28
29
# File 'lib/clockworkd/event.rb', line 25

def run(t)
  eval(@block)
rescue Exception => e
  raise e
end

#time?(t) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/clockworkd/event.rb', line 17

def time?(t)
  if (t.to_i - @next_time.to_i) > 0
    @next_time = @cron_time.next_time
    return true
  end
  false
end

#to_sObject



13
14
15
# File 'lib/clockworkd/event.rb', line 13

def to_s
  @job = job
end