Class: Steady::Task
- Inherits:
-
Object
- Object
- Steady::Task
- Defined in:
- lib/steady.rb
Instance Attribute Summary collapse
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#last_run ⇒ Object
Returns the value of attribute last_run.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(interval, &block) ⇒ Task
constructor
A new instance of Task.
- #needs_running? ⇒ Boolean
- #next_run ⇒ Object
- #run(changes = nil) ⇒ Object
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
#interval ⇒ Object
Returns the value of attribute interval.
103 104 105 |
# File 'lib/steady.rb', line 103 def interval @interval end |
#last_run ⇒ Object
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
115 116 117 |
# File 'lib/steady.rb', line 115 def needs_running? next_run <= Speedytime.current end |
#next_run ⇒ Object
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 |