hotspots 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,8 @@
1
+ v0.3.0
2
+ ------
3
+
4
+ * Optional colours for input and output from git. Use 'ansi' gem for colours
5
+
1
6
  v0.2.0
2
7
  ------
3
8
 
data/README.md CHANGED
@@ -32,6 +32,7 @@ Specific options:
32
32
  All files are allowed when not specified
33
33
  -c, --cutoff [CUTOFF] The minimum occurrence to consider for a file to appear in the list. Defaults to zero
34
34
  -v, --verbose Show verbose output
35
+ -C, --colour, --color Show verbose output in colours
35
36
  --version Show version information
36
37
  -h, --help Show this message
37
38
  ```
data/TODO.md CHANGED
@@ -1,4 +1,3 @@
1
1
  * Allow better use as a library - add documentation
2
2
  * Reduce conditionals
3
- * Optional support for colors
4
3
  * Remove compatibility layers in a major release
@@ -6,7 +6,7 @@ require 'hotspots/repository'
6
6
 
7
7
  module Hotspots
8
8
  class Main
9
- attr_reader :logger, :repository, :verbose,
9
+ attr_reader :logger, :repository, :verbose, :colour,
10
10
  :exit_strategy, :driver, :parser, :store,
11
11
  :time, :message_filters, :file_filter, :cutoff
12
12
 
@@ -18,6 +18,7 @@ module Hotspots
18
18
  @logger = Hotspots::Logger.new
19
19
  @repository = options[:repository]
20
20
  @verbose = options[:verbose]
21
+ @colour = options[:colour]
21
22
  @exit_strategy = options[:exit_strategy]
22
23
 
23
24
  @time = options[:time]
@@ -40,7 +41,7 @@ module Hotspots
40
41
 
41
42
  # TODO : this method should be private
42
43
  def set #:nodoc:
43
- set_logger_if_verbose
44
+ configure_logger
44
45
  set_path
45
46
  assign
46
47
  end
@@ -70,10 +71,14 @@ module Hotspots
70
71
  end
71
72
  end
72
73
 
73
- def set_logger_if_verbose
74
+ def configure_logger
74
75
  if verbose
75
76
  logger.as_console
76
77
  end
78
+
79
+ if colour
80
+ logger.colourize
81
+ end
77
82
  end
78
83
 
79
84
  def set_path
@@ -1,35 +1,63 @@
1
1
  module Hotspots
2
+ # Should understand log levels
2
3
  class Logger #:nodoc: all
3
- class Console
4
- def self.<<(message)
5
- $stdout << message
4
+ module Sink
5
+ class Console
6
+ def self.<<(message)
7
+ $stdout << message
8
+ end
9
+ end
10
+
11
+ class Null
12
+ def self.<<(message)
13
+ end
6
14
  end
7
15
  end
8
16
 
9
- class Null
10
- def self.<<(message)
17
+ module Colour
18
+ class ANSI
19
+ def self.as(colour, message)
20
+ ::ANSI::Code.send(colour, message)
21
+ end
22
+ end
23
+
24
+ class Null
25
+ def self.as(colour, message)
26
+ message
27
+ end
11
28
  end
12
29
  end
13
30
 
14
- attr_reader :sink
31
+ attr_reader :sink, :colour
32
+
15
33
  def initialize
16
- @sink = Null
34
+ @sink = Sink::Null
35
+ @colour = Colour::Null
17
36
  end
18
37
 
19
38
  def as_console
20
- @sink = Console
39
+ @sink = Sink::Console
21
40
  end
22
41
 
23
- # compatibility begin
24
- alias_method :set_console, :as_console
25
- # compatibility end
42
+ def colourize
43
+ require 'ansi/code'
44
+ @colour = Colour::ANSI
45
+ end
26
46
 
27
- def log(message)
28
- @sink << format(message)
47
+ def log(message, options = {})
48
+ sink << format(message, options)
29
49
  end
30
50
 
31
- def format(message)
32
- "[#{Time.now}] #{message}\n"
51
+ # Make this method private
52
+ # Time stampimg should be part of log level
53
+ def format(message, options = {})
54
+ colour.as(options[:as] || "black", "[#{Time.now}] #{message}\n")
33
55
  end
56
+
57
+ # compatibility begin
58
+ alias_method :set_console, :as_console
59
+ Console = Sink::Console
60
+ Null = Sink::Null
61
+ # compatibility end
34
62
  end
35
63
  end
@@ -14,7 +14,8 @@ module Hotspots
14
14
  :message_filters => [""],
15
15
  :cutoff => 0,
16
16
  :verbose => false,
17
- :exit_strategy => OptionBasedExit::Noop.new
17
+ :exit_strategy => OptionBasedExit::Noop.new,
18
+ :colour => false,
18
19
  }
19
20
  end
20
21
  end
@@ -46,6 +47,7 @@ module Hotspots
46
47
  handle_message_filter_on(opts)
47
48
  handle_cutoff_on(opts)
48
49
  handle_verbosity_on(opts)
50
+ handle_colours_on(opts)
49
51
  handle_help_on(opts)
50
52
  end
51
53
  end
@@ -109,6 +111,13 @@ module Hotspots
109
111
  end
110
112
  end
111
113
 
114
+ def handle_colours_on(opts)
115
+ opts.on("-C", "--colour", "--color",
116
+ "Show verbose output in colours") do
117
+ @options[:colour] = true
118
+ end
119
+ end
120
+
112
121
  def handle_help_on(opts)
113
122
  opts.on_tail("-h", "--help",
114
123
  "Show this message") do
@@ -10,18 +10,18 @@ module Hotspots
10
10
 
11
11
  # Input and output should be optionally coloured
12
12
  def pretty_log(options)
13
- command = log_with_tag("Input") { Command::Git::Log.new(:since_days => options[:since_days], :message_filter => options[:message_filter]).build }
14
- log_with_tag("Output") { %x(#{command}) }
13
+ command = log_with_tag("Input", :as => :green) { Command::Git::Log.new(:since_days => options[:since_days], :message_filter => options[:message_filter]).build }
14
+ log_with_tag("Output", :as => :red) { %x(#{command}) }
15
15
  end
16
16
 
17
17
  # Input and output should be optionally coloured
18
18
  def show_one_line_names(options)
19
- command = log_with_tag("Input") { Command::Git::Show.new(:commit_hash => options[:commit_hash]).build }
20
- log_with_tag("Output") { %x(#{command}) }
19
+ command = log_with_tag("Input", :as => :green) { Command::Git::Show.new(:commit_hash => options[:commit_hash]).build }
20
+ log_with_tag("Output", :as => :red) { %x(#{command}) }
21
21
  end
22
22
 
23
- def log_with_tag(tag, &block)
24
- yield.tap { |raw| logger.log "<#{tag}>\n#{raw}<#{tag}/>" }
23
+ def log_with_tag(tag, options, &block)
24
+ yield.tap { |raw| logger.log("<#{tag}>\n#{raw}<#{tag}/>", :as => options[:as]) }
25
25
  end
26
26
  end
27
27
  end
@@ -1,3 +1,3 @@
1
1
  module Hotspots
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -6,38 +6,42 @@ module Hotspots
6
6
  @parser = OptionsParser.new
7
7
  end
8
8
 
9
- describe "defaults" do
10
- it "repository to current path" do
9
+ describe "#initialize" do
10
+ it "defaults repository to current path" do
11
11
  @parser.parse[:repository].must_equal "."
12
12
  end
13
13
 
14
- it "time to 15" do
14
+ it "defaults time to 15" do
15
15
  @parser.parse[:time].must_equal 15
16
16
  end
17
17
 
18
- it "file filter to empty string" do
18
+ it "defaults file filter to empty string" do
19
19
  @parser.parse[:file_filter].must_equal ""
20
20
  end
21
21
 
22
- it "message filters to array with an empty string" do
22
+ it "defaults message filters to array with an empty string" do
23
23
  @parser.parse[:message_filters].must_equal [""]
24
24
  end
25
25
 
26
- it "cutoff to 0" do
26
+ it "defaults cutoff to 0" do
27
27
  @parser.parse[:cutoff].must_equal 0
28
28
  end
29
29
 
30
- it "verbose to nil" do
30
+ it "defaults verbose to nil" do
31
31
  @parser.parse[:verbose].must_equal false
32
32
  end
33
33
 
34
- it "exit code to nil" do
34
+ it "defaults exit code to nil" do
35
35
  @parser.parse[:exit_strategy].code.must_equal nil
36
36
  end
37
37
 
38
- it "exit message to empty string" do
38
+ it "defaults exit message to empty string" do
39
39
  @parser.parse[:exit_strategy].message.must_equal ""
40
40
  end
41
+
42
+ it "defaults colour to false" do
43
+ @parser.parse[:colour].must_equal false
44
+ end
41
45
  end
42
46
 
43
47
  ["--repository", "--repo", "-r"].each do |option|
@@ -108,6 +112,14 @@ module Hotspots
108
112
  end
109
113
  end
110
114
 
115
+ ["--color", "--colour", "-C"].each do |option|
116
+ describe option do
117
+ it "sets colours" do
118
+ @parser.parse(option)[:colour].must_equal true
119
+ end
120
+ end
121
+ end
122
+
111
123
  ["--help", "-h"].each do |option|
112
124
  describe option do
113
125
  it "sets exit code to zero" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotspots
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-26 00:00:00.000000000 Z
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ansi
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: rake
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -113,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
129
  version: '0'
114
130
  segments:
115
131
  - 0
116
- hash: 1394833690291643919
132
+ hash: -2901882375356969213
117
133
  required_rubygems_version: !ruby/object:Gem::Requirement
118
134
  none: false
119
135
  requirements:
@@ -122,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
138
  version: '0'
123
139
  segments:
124
140
  - 0
125
- hash: 1394833690291643919
141
+ hash: -2901882375356969213
126
142
  requirements: []
127
143
  rubyforge_project: hotspots
128
144
  rubygems_version: 1.8.24