loco 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .#*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in todoloco.gemspec
4
+ gemspec
data/README.txt ADDED
@@ -0,0 +1,68 @@
1
+
2
+ rake loco
3
+
4
+ will produce something like this:
5
+
6
+ ### longest files ###
7
+ 145 public/javascripts/validations.js
8
+ 145 spec/models/invoice_spec.rb
9
+ 144 app/models/widget/stage.rb
10
+ 144 app/models/invoice.rb
11
+ 144 app/models/widget/address_extractor.rb
12
+ 143 spec/models/invoice_presenter_spec.rb
13
+ 143 app/helpers/html_helper.rb
14
+ 141 config/routes.rb
15
+ 141 app/controllers/people/people_controller.rb
16
+ 138 spec/models/person_spec.rb
17
+ 138 spec/models/xaction_spec.rb
18
+ 137 app/controllers/welcome_controller.rb
19
+ 135 app/views/invoices/show.html.haml
20
+ 132 spec/support/factory.rb
21
+ 131 app/models/person.rb
22
+ 129 public/javascripts/application.js
23
+
24
+ ### distribution ###
25
+ 0 lines 10 **********
26
+ 1 lines 13 *************
27
+ 5 lines 29 *****************************
28
+ 6 lines 44 ********************************************
29
+ 10 lines 55 **********************************************************
30
+ 11 lines 33 *********************************
31
+ 15 lines 27 ***************************
32
+ 16 lines 27 ***************************
33
+ 20 lines 35 *************************
34
+ 21 lines 29 ********************
35
+ 25 lines 16 ****************
36
+ 26 lines 15 ***************
37
+ 30 lines 15 ***************
38
+ 31 lines 16 ****************
39
+ 35 lines 12 ************
40
+ 36 lines 13 *************
41
+ 40 lines 9 *********
42
+ 41 lines 11 ***********
43
+ 45 lines 9 *********
44
+ 46 lines 11 ***********
45
+ 50 lines 5 *****
46
+ 51 lines 8 ********
47
+ 52 lines 2 **
48
+ 53 lines 8 ********
49
+ 54 lines 9 *********
50
+ 55 lines 4 ****
51
+ 56 lines 5 *****
52
+ 69 lines 3 ***
53
+ 71 lines 1 *
54
+ 80 lines 2 **
55
+ 95 lines 1 *
56
+ 128 lines 1 *
57
+
58
+ ### extensions ###
59
+ .rb - 791 files, 25907 lines
60
+ .haml - 391 files, 6938 lines
61
+ .yml - 173 files, 7512 lines
62
+ .rake - 8 files, 383 lines
63
+ .html - 4 files, 179 lines
64
+ .js - 14 files, 840 lines
65
+
66
+ == License
67
+
68
+ Loco is released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/lib/loco.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "loco/version"
2
+
3
+ module Loco
4
+ require 'loco/railtie' if defined?(Rails)
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'loco'
2
+ require 'rails'
3
+ module Loco
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ load "tasks/loco.rake"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Loco
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,134 @@
1
+ namespace :loco do
2
+ @exclude = [
3
+ /^db\/schema.rb/,
4
+ /^db\/epg_timetable.yml/,
5
+ /^db\/backups/,
6
+ /^vendor/,
7
+ /^public\/system/,
8
+ /^public\/images/,
9
+ /^public\/stylesheets/,
10
+ /^config\/newrelic.yml/,
11
+ /^tmp/,
12
+ /^coverage/,
13
+ /^log/,
14
+ /^doc/,
15
+ /^script/,
16
+ /^stories/,
17
+ /^static/,
18
+ /^public\/fonts/,
19
+ /\.#.+/,
20
+ /\.png/,
21
+ /\.pdf/,
22
+ /\.ico/,
23
+ /lib\/tasks\/.+\.txt/,
24
+ /^README/,
25
+ /^Gemfile.lock/,
26
+ /^public\/javascripts\/jquery/
27
+ ]
28
+
29
+ def exclude? path
30
+ @exclude.each { |regex|
31
+ if path =~ regex
32
+ return true
33
+ end
34
+ }
35
+ false
36
+ end
37
+
38
+ def align x
39
+ x.to_s.rjust(8, " ")
40
+ end
41
+
42
+ class Stats
43
+ attr_accessor :path, :lines
44
+ def initialize(path)
45
+ @path = path
46
+ @lines = count_lines(path)
47
+ end
48
+
49
+ def count_lines path
50
+ File.read(path).split(/\n/).inject(0) {|sum, line| sum + (line.blank? ? 0 : 1) }
51
+ end
52
+
53
+ def to_s
54
+ "#{align lines} #{path}"
55
+ end
56
+
57
+ def matches options
58
+ options[:size].blank? || (options[:size] == 0 && lines == 0)
59
+ end
60
+ end
61
+
62
+ def analyse_loc regexp, opts={ }
63
+ @stats = []
64
+ @exts = Hash.new { |h, k| h[k] = 0 }
65
+ @ext_lines = Hash.new { |h, k| h[k] = 0 }
66
+ @sizes = Hash.new { |h, k| h[k] = [] }
67
+ total_lines = 0
68
+
69
+ Dir.glob("#{Rails.root}/**/*").each do |full_path|
70
+ unless File.stat(full_path).directory?
71
+ path = full_path.sub(Rails.root.to_s + "/", '')
72
+ unless exclude?(path) || !regexp.match(path)
73
+ s = Stats.new(path)
74
+ if s.matches(opts)
75
+ @stats << s
76
+ @exts[File.extname(path)] += 1
77
+ @ext_lines[File.extname(path)] += s.lines
78
+ @sizes[s.lines] << path
79
+ total_lines += s.lines
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ puts "\n### extensions ###"
86
+ @exts.each { |ext, count| puts "#{align ext} - #{align count} files, #{align @ext_lines[ext]} lines"}
87
+
88
+ puts "\n### distribution ###"
89
+ @sizes = @sizes.to_a.sort { |a, b|
90
+ a[0] <=> b[0]
91
+ }
92
+
93
+ @sizes.each { |size, files|
94
+ puts "#{align size} lines #{align files.size} #{"*" * files.size}"
95
+ }
96
+
97
+ total = @stats.size
98
+ @stats = @stats.sort { |a, b| b.lines <=> a.lines }
99
+ @stats = @stats[0..40] if @stats.size > 40
100
+
101
+ puts "\n### longest files ###"
102
+ @stats.each { |s| puts s }
103
+
104
+ puts "\n### Total #{regexp.inspect} : #{total} files, #{total_lines} lines, #{"%.3f" % (1.0 * total_lines / total)} avg loc per file ###"
105
+ end
106
+
107
+ desc "show loc for all files"
108
+ task(:all) { analyse_loc /.*/ }
109
+
110
+ desc "show loc for all .js files"
111
+ task(:js) { analyse_loc /.*\.js$/ }
112
+
113
+ desc "show loc for all .rb files"
114
+ task(:rb) { analyse_loc /.*\.rb$/ }
115
+
116
+ desc "show loc for all .haml files"
117
+ task(:haml) { analyse_loc /.*\.haml$/ }
118
+
119
+ desc "show loc for all app/** files"
120
+ task(:app) { analyse_loc /^app\// }
121
+
122
+ desc "show loc for all app/models/** files"
123
+ task(:models) { analyse_loc /^app\/models\// }
124
+
125
+ desc "show loc for all spec/** files"
126
+ task(:spec) { analyse_loc /^spec\// }
127
+
128
+ desc "show details for empty files"
129
+ task(:empty) { analyse_loc /.*/, :size => 0 }
130
+ end
131
+
132
+ task :loco => "loco:all"
133
+
134
+
data/loco.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require "loco/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "loco"
8
+ s.version = Loco::VERSION
9
+ s.authors = ["conanite"]
10
+ s.email = ["conan@conandalton.net"]
11
+ s.homepage = "https://github.com/conanite/loco"
12
+ s.summary = %q{Produce statistics concerning numbers of lines of code in project files}
13
+ s.description = %q{Count lines of code in project files, excluding a bunch of common defaults, and show (a) for each N, how many files have N lines of code; (b) how many files of each type and average LOC per file of that type; (c) longest files and their length }
14
+
15
+ s.rubyforge_project = "loco"
16
+
17
+ # warning: ensure ENV["PATH"] can find your git executable
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: loco
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - conanite
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-20 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'Count lines of code in project files, excluding a bunch of common
15
+ defaults, and show (a) for each N, how many files have N lines of code; (b) how
16
+ many files of each type and average LOC per file of that type; (c) longest files
17
+ and their length '
18
+ email:
19
+ - conan@conandalton.net
20
+ executables: []
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - .gitignore
25
+ - Gemfile
26
+ - README.txt
27
+ - Rakefile
28
+ - lib/loco.rb
29
+ - lib/loco/railtie.rb
30
+ - lib/loco/version.rb
31
+ - lib/tasks/loco.rake
32
+ - loco.gemspec
33
+ homepage: https://github.com/conanite/loco
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project: loco
53
+ rubygems_version: 1.8.24
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Produce statistics concerning numbers of lines of code in project files
57
+ test_files: []