simplificator-flogger 0.1.1 → 0.2.5

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.
Files changed (3) hide show
  1. data/README +35 -0
  2. data/lib/flogger/assertions.rb +11 -7
  3. metadata +2 -1
data/README ADDED
@@ -0,0 +1,35 @@
1
+ = flogger
2
+ == What is it
3
+ It's a test/unit extension so you can unit test your flog scores
4
+
5
+
6
+ == Installation
7
+ sudo gem install flog
8
+ sudo gem install simplificator-flogger
9
+
10
+ == usage
11
+ In your unit tests do
12
+
13
+ def test_something
14
+ assert_flog(a_file_or_a_dir)
15
+ end
16
+
17
+ = Samples:
18
+ == Flog a file or all ruby files in a directory
19
+ assert_flog(file_or_dir)
20
+ == Flog several files or directories
21
+ assert_flog(file_or_dir_1, file_or_dir_2, file_or_fir_n)
22
+ == set your own flog threshold
23
+ assert_flog(file_or_dir, :threshold => 20)
24
+ == set your own flog threshold for a specific method
25
+ assert_flog(file_or_dir, :thresholds => {'FooClass#bar_method'})
26
+
27
+ = Credits
28
+ Thanks to the ruby sadists at http://ruby.sadi.st/Ruby_Sadist.html
29
+
30
+ = More
31
+ See lib/flogger/assertions.rb for more
32
+
33
+ = About us
34
+ Simplificator writes Ruby and Ruby on Rails apps for a living.
35
+ http://simplificator.com
@@ -1,5 +1,8 @@
1
1
  module Flogger
2
2
  module InstanceMethods
3
+ ERROR_MESSAGE_PREFIX = 'Error when flogging your files:'
4
+ ERROR_MESSAGE = "%s has a flog score of %.2f (exceeding treshold of %.2f by %.2f)"
5
+
3
6
  #
4
7
  # assert the flog score of file(s) is below a treshold (default treshold is 20).
5
8
  #
@@ -27,7 +30,7 @@ module Flogger
27
30
  options = {:treshold => 20}.merge(options)
28
31
  flogger = Flog.new()
29
32
  flogger.flog_files(files)
30
- failures = reject_success(flogger.totals, options)
33
+ failures = reject_success_and_sort(flogger.totals, options)
31
34
  assert_block(build_flog_message(failures, options)) do
32
35
  failures.size == 0
33
36
  end
@@ -50,10 +53,11 @@ module Flogger
50
53
  # Builds a 'nice' error message listing all failed methods
51
54
  #
52
55
  def build_flog_message(failures, options)
53
- message = ['Error when flogging your files:']
54
- failures.each do |key, value|
55
- limit = treshold_for_key(key, options)
56
- message << "#{key.ljust(40, ' ')} has a flog score of #{value} (exceeding treshold of #{limit} by #{value - limit})"
56
+ max = failures.inject(0) {|memo, item| memo = [memo, item.first.length].max}
57
+ message = [ERROR_MESSAGE_PREFIX]
58
+ failures.each do |item|
59
+ limit = treshold_for_key(item.first, options)
60
+ message << ERROR_MESSAGE % [item.first.ljust(max + 2, ' '), item.last, limit, (item.last - limit)]
57
61
  end
58
62
  message.join("\n")
59
63
  end
@@ -61,10 +65,10 @@ module Flogger
61
65
  #
62
66
  # Remove all values which are not exceeding the threshold
63
67
  #
64
- def reject_success(totals, options)
68
+ def reject_success_and_sort(totals, options)
65
69
  totals.reject do |key, value|
66
70
  value < treshold_for_key(key, options)
67
- end
71
+ end.to_a.sort() {|a, b| b.last <=> a.last}
68
72
  end
69
73
 
70
74
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplificator-flogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simplificator GmbH
@@ -24,6 +24,7 @@ extra_rdoc_files: []
24
24
  files:
25
25
  - lib/flogger.rb
26
26
  - lib/flogger/assertions.rb
27
+ - README
27
28
  has_rdoc: false
28
29
  homepage: http://simplificator.com/en/lab
29
30
  post_install_message: