Class: SkadateGems::Dev::Remote::CloneLogger
- Inherits:
-
Object
- Object
- SkadateGems::Dev::Remote::CloneLogger
- Defined in:
- lib/skadategems/dev/remote/clone_logger.rb
Class Method Summary collapse
Instance Method Summary collapse
- #entry(entry, status = nil, label = nil) { ... } ⇒ Object
-
#initialize(file_io) ⇒ CloneLogger
constructor
A new instance of CloneLogger.
- #print(obj, *rest) ⇒ Object
- #puts(line, color = nil) ⇒ Object
- #set_color(string, *colors) ⇒ Object
- #write(string) ⇒ Object
Constructor Details
#initialize(file_io) ⇒ CloneLogger
Returns a new instance of CloneLogger.
16 17 18 19 |
# File 'lib/skadategems/dev/remote/clone_logger.rb', line 16 def initialize(file_io) @file_io = file_io super() end |
Class Method Details
.start(log_file_path, &block) ⇒ Object
10 11 12 13 14 |
# File 'lib/skadategems/dev/remote/clone_logger.rb', line 10 def self.start(log_file_path, &block) ::File.open(log_file_path, 'w') do |file_io| block.call new(file_io) end end |
Instance Method Details
#entry(entry, status = nil, label = nil) { ... } ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/skadategems/dev/remote/clone_logger.rb', line 25 def entry(entry, status = nil, label = nil) icon = if status == :skipped '*' elsif entry.is_a?(Directory) '=' elsif entry.is_a?(File) '~' end prefix = "#{' ' * padding}#{icon}>" print(if entry.is_a?(Directory) "#{prefix} #{set_color(entry.path, :blue)}" elsif entry.is_a?(File) "#{prefix} #{set_color(entry.basename, :white)} (#{set_color(entry.friendly_size, :cyan)})" else "#{prefix} #{set_color(entry.to_s, :on_black)}" end) write(if entry.is_a?(Directory) "#{prefix} #{entry.path}" elsif entry.is_a?(File) "#{prefix} #{entry.basename} (#{entry.friendly_size})" else "#{prefix} #{entry}" end) if status == :skipped label ||= 'skipped' print(" [#{set_color(label, :magenta)}]") write(" [#{label}]") end if block_given? print ' ...' stdout.flush status = yield label, color = case status when :downloaded ['downloaded', :green] when :unchanged ['unchanged', :cyan] else # no status badge end if label print "\b" * 4 if can_display_colors? print(" [#{set_color(label, color)}]") write(" [#{label}]") end end rescue print "\b" * 4 if can_display_colors? print " [#{set_color('error', :red)}]" write " [error]\n#{'>' * 30}\n[#{$!.class.name}]: #{$!.}\n#{'-' * 30}" raise $! ensure print "\n" write "\n" stdout.flush end |
#print(obj, *rest) ⇒ Object
107 108 109 |
# File 'lib/skadategems/dev/remote/clone_logger.rb', line 107 def print(obj, *rest) super unless mute? end |
#puts(line, color = nil) ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/skadategems/dev/remote/clone_logger.rb', line 94 def puts(line, color = nil) unless mute? super set_color(line, color) stdout.flush end write "#{line}\n" end |
#set_color(string, *colors) ⇒ Object
103 104 105 |
# File 'lib/skadategems/dev/remote/clone_logger.rb', line 103 def set_color(string, *colors) can_display_colors? ? super(string, *colors) : string end |
#write(string) ⇒ Object
111 112 113 |
# File 'lib/skadategems/dev/remote/clone_logger.rb', line 111 def write(string) @file_io << string if @file_io end |