Class: Sh::Log::Broadcaster

Inherits:
Object show all
Defined in:
lib/sh_log.rb

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Broadcaster

Returns a new instance of Broadcaster.



4
5
6
# File 'lib/sh_log.rb', line 4

def initialize type
	@type = type
end

Instance Method Details

#flushObject



18
19
20
21
22
23
24
25
26
# File 'lib/sh_log.rb', line 18

def flush
  case @type
  when :stderr
    Log.error "> #{@buffer}"
  when :stdout
    Log.info "> #{@buffer}"
  end
  @buffer = ""
end

#puts(str) ⇒ Object



14
15
16
# File 'lib/sh_log.rb', line 14

def puts str
	write "#{str}\n"
end

#write(str) ⇒ Object



8
9
10
11
12
# File 'lib/sh_log.rb', line 8

def write str
	@buffer ||= ""
	@buffer << str
	flush if @buffer.end_with? "\n"
end