class Potassium::TextSpinner

TODO: I don’t know if this is a concern of this gem. Maybe we should move this later

Constants

DEFAULT_ATTRIBUTES

Attributes

base_message[RW]
counter[RW]
interval[RW]
message_continuations[RW]
started[RW]
wait_condition[RW]

Public Class Methods

new(attributes = {}) click to toggle source
# File lib/potassium/text_spinner.rb, line 14
def initialize(attributes = {})
  DEFAULT_ATTRIBUTES.merge(attributes).each do |key, value|
    public_send("#{key}=", value)
  end
  self.started = false
  self.counter = 0
end

Public Instance Methods

start() click to toggle source
# File lib/potassium/text_spinner.rb, line 22
def start
  fail already_started_message if started
  self.started = true

  Thread.new do
    loop do
      break if wait_condition.call(counter)
      print_message
      sleep interval
      self.counter += 1
    end
    self.started = false
  end
end

Private Instance Methods

already_started_message() click to toggle source
# File lib/potassium/text_spinner.rb, line 46
def already_started_message
  "Please don't start this text spinner while is running. It can cause race conditions."
end
print_message() click to toggle source