class Spring::ProcessTitleUpdater
load time down.
I don’t want the spring client to depend on AS, in order to keep its
Yes, I know this reimplements a bunch of stuff in Active Support, but
def self.run(&block)
def self.run(&block) updater = new(&block) Thread.new { $0 = updater.value loop { $0 = updater.next } } end
def distance_in_words(now = Time.now)
def distance_in_words(now = Time.now) distance = now - @start if distance < MINUTE pluralize(distance, "sec") elsif distance < HOUR pluralize(distance / MINUTE, "min") else pluralize(distance / HOUR, "hour") end end
def initialize(start = Time.now, &block)
def initialize(start = Time.now, &block) @start = start @block = block end
def interval
def interval distance = Time.now - @start if distance < MINUTE SECOND elsif distance < HOUR MINUTE else HOUR end end
def next
def next sleep interval value end
def pluralize(amount, unit)
def pluralize(amount, unit) "#{amount.to_i} #{amount.to_i == 1 ? unit : "#{unit}s"}" end
def value
def value block.call(distance_in_words) end