class Sassmagic::Installers::Logger

logger

Constants

ACTION_CAN_BE_QUIET
ACTION_COLORS
COLORS
DEFAULT_ACTIONS

Attributes

actions[RW]
options[RW]
time[RW]

Public Class Methods

new(*actions) click to toggle source
# File lib/sassmagic/installer.rb, line 213
def initialize(*actions)
  self.options = actions.last.is_a?(Hash) ? actions.pop : {}
  @actions = DEFAULT_ACTIONS.dup
  @actions += actions
end

Public Instance Methods

action_padding(action) click to toggle source

add padding to the left of an action that was performed.

# File lib/sassmagic/installer.rb, line 280
def action_padding(action)
  ' ' * [(max_action_length - action.to_s.length), 0].max
end
color(c) click to toggle source
# File lib/sassmagic/installer.rb, line 255
def color(c)
  if c && COLORS.has_key?(c.to_sym)
    if defined?($boring) && $boring
      ""
    else
      "\e[#{COLORS[c.to_sym]}m"
    end
  else
    ""
  end
end
emit(msg) click to toggle source

Emit a log message without a trailing newline

# File lib/sassmagic/installer.rb, line 268
def emit(msg)
  print msg
  $stdout.flush
end
green() { || ... } click to toggle source
# File lib/sassmagic/installer.rb, line 233
def green
  wrap(:green) { yield }
end
log(msg) click to toggle source

Emit a log message with a trailing newline

# File lib/sassmagic/installer.rb, line 274
def log(msg)
  puts msg
  $stdout.flush
end
max_action_length() click to toggle source

the maximum length of all the actions known to the logger.

# File lib/sassmagic/installer.rb, line 285
def max_action_length
  @max_action_length ||= actions.inject(0){|memo, a| [memo, a.to_s.length].max}
end
record(action, *arguments) click to toggle source

Record an action that has occurred

# File lib/sassmagic/installer.rb, line 220
def record(action, *arguments)
  return if options[:quiet] && ACTION_CAN_BE_QUIET[action]
  msg = ""
  if time
    msg << Time.now.strftime("%I:%M:%S.%3N %p")
  end
  msg << color(ACTION_COLORS[action])
  msg << "#{action_padding(action)}#{action}"
  msg << color(:clear)
  msg << " #{arguments.join(' ')}"
  log msg
end
red() { || ... } click to toggle source
# File lib/sassmagic/installer.rb, line 237
def red
  wrap(:red) { yield }
end
wrap(c, reset_to = :clear) { || ... } click to toggle source
# File lib/sassmagic/installer.rb, line 245
def wrap(c, reset_to = :clear)
  $stderr.write(color(c))
  $stdout.write(color(c))
  yield
ensure
  $stderr.write(color(reset_to))
  $stdout.write(color(reset_to))
  $stdout.flush
end
yellow() { || ... } click to toggle source
# File lib/sassmagic/installer.rb, line 241
def yellow
  wrap(:yellow) { yield }
end