Sha256: 16aa90c9b6d774390a9f07684feee4272dfc5d7e3bf7ba9343946a15be567e87

Contents?: true

Size: 1.28 KB

Versions: 29

Compression:

Stored size: 1.28 KB

Contents

module Hydra #:nodoc:
  module Listener #:nodoc:
    # Output a progress bar as files are completed
    class ProgressBar < Hydra::Listener::Abstract
      # Store the total number of files
      def testing_begin(files)
        @total_files = files.size
        @files_completed = 0
        @test_output = ""
        @errors = false
        render_progress_bar
      end

      # Increment completed files count and update bar
      def file_end(file, output)
        unless output == '.'
          @output.write "\r#{' '*60}\r#{output}\n"
          @errors = true
        end
        @files_completed += 1
        render_progress_bar
      end

      # Break the line
      def testing_end
        render_progress_bar
        @output.write "\n"
      end

      private

      def render_progress_bar
        width = 30
        complete = ((@files_completed.to_f / @total_files.to_f) * width).to_i
        @output.write "\r" # move to beginning
        @output.write 'Hydra Testing ['
        @output.write @errors ? "\033[0;31m" : "\033[0;32m"
        complete.times{@output.write '#'}
        @output.write '>'
        (width-complete).times{@output.write ' '}
        @output.write "\033[0m"
        @output.write "] #{@files_completed}/#{@total_files}"
        @output.flush
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 8 rubygems

Version Path
ngauthier-hydra-0.24.0 lib/hydra/listener/progress_bar.rb
nulogy-hydra-0.26.0 lib/hydra/listener/progress_bar.rb
arturop-hydra-0.25.0 lib/hydra/listener/progress_bar.rb
arturop-hydra-0.24.0 lib/hydra/listener/progress_bar.rb
hydra-0.24.0 lib/hydra/listener/progress_bar.rb
nulogy-hydra-0.23.2.1 lib/hydra/listener/progress_bar.rb
justinf-hydra-0.23.8 lib/hydra/listener/progress_bar.rb
justinf-hydra-0.23.7 lib/hydra/listener/progress_bar.rb
justinf-hydra-0.23.6 lib/hydra/listener/progress_bar.rb
justinf-hydra-0.23.5 lib/hydra/listener/progress_bar.rb
justinf-hydra-0.23.4 lib/hydra/listener/progress_bar.rb
arturop-hydra-0.23.4 lib/hydra/listener/progress_bar.rb
sskirby-hydra-0.23.3 lib/hydra/listener/progress_bar.rb
hydra-0.23.3 lib/hydra/listener/progress_bar.rb
causes-hydra-0.21.0 lib/hydra/listener/progress_bar.rb
hydra-0.23.2 lib/hydra/listener/progress_bar.rb
hydra-0.23.1 lib/hydra/listener/progress_bar.rb
hydra-0.23.0 lib/hydra/listener/progress_bar.rb
hydra-0.22.2 lib/hydra/listener/progress_bar.rb
hydra-0.22.1 lib/hydra/listener/progress_bar.rb