bumbler 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.unshift File.expand_path("../lib", __FILE__)
3
- require "bumbler/version"
2
+ require File.expand_path("../lib/bumbler.rb", __FILE__)
4
3
 
5
4
  Gem::Specification.new do |s|
6
5
  s.name = "bumbler"
@@ -1,4 +1,7 @@
1
1
  module Bumbler
2
+ # We can be required twice due to the command line require
3
+ VERSION = '0.1.2' unless self.const_defined? :VERSION
4
+
2
5
  autoload :Hooks, 'bumbler/hooks'
3
6
  autoload :Bundler, 'bumbler/bundler'
4
7
  autoload :Progress, 'bumbler/progress'
@@ -7,6 +7,13 @@ module Bumbler
7
7
  return @require_map[path]
8
8
  end
9
9
 
10
+ def self.require_started(path)
11
+ gem_name = self.gem_for_require(path)
12
+ return unless gem_name
13
+
14
+ Bumbler::Progress.item_started(:bundler, gem_name)
15
+ end
16
+
10
17
  def self.require_finished(path, load_time)
11
18
  self.read_bundler_environment if @gem_state.nil?
12
19
 
@@ -54,6 +54,11 @@ module Bumbler
54
54
  gem_name = Bumbler::Bundler.gem_for_require(path)
55
55
  return yield unless gem_name
56
56
 
57
+ # Track load starts
58
+ @previous_gems ||= {}
59
+ Bumbler::Bundler.require_started(path) unless @previous_gems[gem_name]
60
+ @previous_gems[gem_name] = true
61
+
57
62
  # Let's time them
58
63
  start = Time.now.to_f
59
64
  result = yield
@@ -11,19 +11,26 @@ module Bumbler
11
11
  self.registry[type][name] = {}
12
12
  end
13
13
 
14
+ def self.item_started(type, name)
15
+ @curr_item = {:type => type, :name => name}
16
+
17
+ self.render_progress
18
+ end
19
+
14
20
  def self.item_finished(type, name, time)
15
21
  self.registry[type][name] = {:time => time}
16
22
 
17
23
  @loaded_items ||= 0
18
24
  @loaded_items += 1
19
25
 
20
- time_str = ('%.2fms' % time).rjust(9)
21
- self.render_progress('%s loaded %s ' % [time_str, name])
26
+ @prev_item = {:type => type, :name => name, :time => time}
27
+ @curr_item = nil if @curr_item && @curr_item[:name] == @prev_item[:name] && @curr_item[:type] == @prev_item[:type]
28
+
29
+ self.render_progress
22
30
  end
23
31
 
24
32
  def self.start!
25
- @loaded_items ||= 0
26
- @item_count ||= 0
33
+ # No-op for now.
27
34
  end
28
35
 
29
36
  private
@@ -36,8 +43,8 @@ module Bumbler
36
43
  `tput cols`.to_i || 80
37
44
  end
38
45
 
39
- def self.bar
40
- inner_size = self.tty_width - 2
46
+ def self.bar(width)
47
+ inner_size = width - 2
41
48
 
42
49
  fill_size = ((@loaded_items.to_f / @item_count.to_f) * inner_size).to_i
43
50
  fill = '#' * fill_size
@@ -46,15 +53,43 @@ module Bumbler
46
53
  return "[#{fill}#{empty}]"
47
54
  end
48
55
 
49
- def self.render_progress(message)
50
- if $stdout.tty?
51
- print "\r\e[A\r\e[K\r\e[A" if @outputted_once
52
- @outputted_once = true
53
-
54
- puts self.bar
56
+ def self.render_progress
57
+ unless $stdout.tty?
58
+ puts '(%s/%d) %s' % [@loaded_items.to_s.rjust(@item_count.to_s.size), @item_count, message]
59
+ return
55
60
  end
56
61
 
57
- puts '(%s/%d) %s' % [@loaded_items.to_s.rjust(@item_count.to_s.size), @item_count, message]
62
+ # Do nothing if we don't have any items to load
63
+ return if @item_count == 0
64
+
65
+ width = self.tty_width
66
+
67
+ print "\r\e[A\r\e[A" if @outputted_once
68
+ @outputted_once = true
69
+
70
+ @loaded_items ||= 0
71
+ @item_count ||= 0
72
+
73
+ # Output components:
74
+ # [#######################################]
75
+ # (##/##) <current>... <prev> (####.##ms)
76
+ #
77
+ # Skip the current if there isn't enough room
78
+ count = '(%s/%d) ' % [@loaded_items.to_s.rjust(@item_count.to_s.size), @item_count]
79
+ current = @curr_item ? "#{@curr_item[:name]}... " : ''
80
+ prev = @prev_item ? '%s (%sms)' % [@prev_item[:name], ('%.2f' % @prev_item[:time]).rjust(7)] : ''
81
+
82
+ # Align the bottom row
83
+ space_for_current = width - (count.length + prev.length)
84
+
85
+ # Render the progress
86
+ puts self.bar(width)
87
+
88
+ if space_for_current >= current.length
89
+ puts count + current + prev.rjust(width - count.length - current.length)
90
+ else
91
+ puts count + prev.rjust(width - count.length)
92
+ end
58
93
  end
59
94
  end
60
95
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: bumbler
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ian MacLeod
@@ -34,7 +34,6 @@ files:
34
34
  - lib/bumbler/go.rb
35
35
  - lib/bumbler/hooks.rb
36
36
  - lib/bumbler/progress.rb
37
- - lib/bumbler/version.rb
38
37
  has_rdoc: true
39
38
  homepage: https://github.com/nevir/Bumbler
40
39
  licenses: []
@@ -1,3 +0,0 @@
1
- module Bumbler
2
- VERSION = "0.1.1"
3
- end