Class: Steady::Task

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interval, &block) ⇒ Task

Returns a new instance of Task.



105
106
107
108
109
# File 'lib/steady.rb', line 105

def initialize(interval, &block)
  @interval = interval
  @proc = block
  @last_run = 0
end

Instance Attribute Details

#intervalObject

Returns the value of attribute interval.



103
104
105
# File 'lib/steady.rb', line 103

def interval
  @interval
end

#last_runObject

Returns the value of attribute last_run.



103
104
105
# File 'lib/steady.rb', line 103

def last_run
  @last_run
end

Instance Method Details

#<=>(other) ⇒ Object



129
130
131
# File 'lib/steady.rb', line 129

def <=>(other)
  next_run <=> other.next_run
end

#needs_running?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/steady.rb', line 115

def needs_running?
  next_run <= Speedytime.current
end

#next_runObject



111
112
113
# File 'lib/steady.rb', line 111

def next_run
  @last_run + @interval
end

#run(changes = nil) ⇒ Object



119
120
121
122
123
124
125
126
127
# File 'lib/steady.rb', line 119

def run(changes = nil)
  if needs_running?
    @proc.call(changes)
    @last_run = Speedytime.current
    true
  else
    false
  end
end