code_metrics 0.0.3 → 0.1.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.
- data/Rakefile +12 -9
- data/lib/code_metrics/railtie.rb +0 -1
- data/lib/code_metrics/statistics.rb +1 -7
- data/lib/code_metrics/stats_directories.rb +122 -18
- data/lib/code_metrics/version.rb +1 -1
- data/test/dummy/config/application.rb +8 -2
- data/test/dummy/config/environments/development.rb +0 -17
- data/test/dummy/config/environments/production.rb +0 -35
- data/test/dummy/config/environments/test.rb +0 -22
- metadata +13 -23
- checksums.yaml +0 -7
data/Rakefile
CHANGED
@@ -4,19 +4,22 @@ rescue LoadError
|
|
4
4
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
5
|
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
rdoc
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
|
10
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
11
|
+
rdoc.rdoc_dir = 'rdoc'
|
12
|
+
rdoc.title = 'CodeMetrics'
|
13
|
+
rdoc.options << '--line-numbers'
|
14
|
+
rdoc.rdoc_files.include('README.rdoc')
|
15
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
16
|
+
end
|
17
|
+
rescue LoadError, StandardError => e
|
18
|
+
warn "Setting up rdoc failed #{e.class}: #{e.message}: #{__FILE__}:#{__LINE__}"
|
15
19
|
end
|
16
20
|
|
17
21
|
|
18
22
|
|
19
|
-
|
20
23
|
Bundler::GemHelper.install_tasks
|
21
24
|
|
22
25
|
require 'rake/testtask'
|
data/lib/code_metrics/railtie.rb
CHANGED
@@ -4,13 +4,7 @@ require 'code_metrics/stats_directories'
|
|
4
4
|
module CodeMetrics
|
5
5
|
class Statistics
|
6
6
|
|
7
|
-
TEST_TYPES = [
|
8
|
-
'Helper tests',
|
9
|
-
'Model tests',
|
10
|
-
'Mailer tests',
|
11
|
-
'Integration tests',
|
12
|
-
'Functional tests (old)',
|
13
|
-
'Unit tests (old)']
|
7
|
+
TEST_TYPES = []
|
14
8
|
|
15
9
|
def initialize(*pairs)
|
16
10
|
@pairs = pairs
|
@@ -1,28 +1,132 @@
|
|
1
1
|
# Try to get the root of the current project
|
2
|
+
require 'pathname'
|
2
3
|
module CodeMetrics
|
3
4
|
class StatsDirectories
|
5
|
+
StatDirectory = Struct.new(:description, :path) do
|
6
|
+
def to_a
|
7
|
+
[description, path]
|
8
|
+
end
|
9
|
+
def inspect
|
10
|
+
to_a.inspect
|
11
|
+
end
|
12
|
+
def directory?
|
13
|
+
File.directory?(path)
|
14
|
+
end
|
15
|
+
def name(file_pattern)
|
16
|
+
path.sub(/^\.\/(#{file_pattern}\/\w+)\/.*/, '\\1')
|
17
|
+
end
|
18
|
+
def self.from_list(list, path_prefix='')
|
19
|
+
list.map do |description, path|
|
20
|
+
new(description, [path_prefix,path].compact.join('/'))
|
21
|
+
end.select(&:directory?)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :app_directories, :test_directories
|
26
|
+
|
4
27
|
def initialize
|
5
|
-
@root =
|
28
|
+
@root = path_prefix
|
29
|
+
@app_directories = default_app_directories
|
30
|
+
@test_directories = default_test_directories
|
6
31
|
end
|
32
|
+
|
7
33
|
def directories
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
34
|
+
app_directories.map(&:to_a) | test_directories.map(&:to_a)
|
35
|
+
end
|
36
|
+
|
37
|
+
# What Rails expects
|
38
|
+
def default_app_directories
|
39
|
+
StatDirectory.from_list([
|
40
|
+
%w(Controllers app/controllers),
|
41
|
+
%w(Helpers app/helpers),
|
42
|
+
%w(Models app/models),
|
43
|
+
%w(Mailers app/mailers),
|
44
|
+
%w(Javascripts app/assets/javascripts),
|
45
|
+
%w(Libraries lib),
|
46
|
+
%w(APIs app/apis)
|
47
|
+
], @root)
|
48
|
+
end
|
49
|
+
|
50
|
+
def default_test_directories
|
51
|
+
StatDirectory.from_list([
|
52
|
+
%w(Controller\ tests test/controllers),
|
53
|
+
%w(Helper\ tests test/helpers),
|
54
|
+
%w(Model\ tests test/models),
|
55
|
+
%w(Mailer\ tests test/mailers),
|
56
|
+
%w(Integration\ tests test/integration),
|
57
|
+
%w(Functional\ tests\ (old) test/functional),
|
58
|
+
%w(Unit\ tests \ (old) test/unit)
|
59
|
+
], @root)
|
60
|
+
end
|
61
|
+
|
62
|
+
# @example add_directories('./spec/**/*_spec.rb', 'spec')
|
63
|
+
# will build dirs with the format of description, path:
|
64
|
+
# [ 'Acceptance specs', 'spec/acceptance' ]
|
65
|
+
def add_directories(dir_pattern, file_pattern)
|
66
|
+
build_directories(dir_pattern, file_pattern).each do |description, path|
|
67
|
+
add_directory(description, path)
|
68
|
+
end
|
69
|
+
self
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_test_directories(dir_pattern, file_pattern)
|
73
|
+
build_directories(dir_pattern, file_pattern).each do |description, path|
|
74
|
+
add_test_directory(description, path)
|
75
|
+
end
|
76
|
+
self
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_directory(description,folder_path)
|
80
|
+
folder_path = folder_path.to_s
|
81
|
+
unless app_directories.any?{|stat_dir| stat_dir.path == folder_path}
|
82
|
+
app_directories << StatDirectory.new(description, folder_path)
|
83
|
+
end
|
84
|
+
self
|
85
|
+
end
|
86
|
+
|
87
|
+
def add_test_directory(description,folder_path)
|
88
|
+
folder_path = folder_path.to_s
|
89
|
+
unless test_directories.any?{|stat_dir| stat_dir.path == folder_path}
|
90
|
+
test_directories << StatDirectory.new(description, folder_path)
|
91
|
+
CodeMetrics::Statistics::TEST_TYPES << description
|
92
|
+
end
|
93
|
+
self
|
94
|
+
end
|
95
|
+
|
96
|
+
# @example build_directories('./spec/**/*_spec.rb', 'spec')
|
97
|
+
def build_directories(glob_pattern, file_pattern)
|
98
|
+
dirs = collect_directories(glob_pattern, file_pattern)
|
99
|
+
|
100
|
+
Hash[dirs.map { |path|
|
101
|
+
[description(path.basename,file_pattern), path]
|
102
|
+
}
|
103
|
+
]
|
104
|
+
end
|
105
|
+
# collects non empty directories and names the metric by the folder name
|
106
|
+
# parent? or dirname? or basename?
|
107
|
+
def collect_directories(glob_pattern, file_pattern='')
|
108
|
+
Pathname.glob(glob_pattern).select{|f| f.basename.to_s.include?(file_pattern) }.map(&:dirname).uniq.map(&:realpath)
|
109
|
+
end
|
110
|
+
|
111
|
+
def description(path_basename,file_pattern)
|
112
|
+
if path_basename.to_s == file_pattern
|
113
|
+
"Uncategorized #{pluralize(file_pattern)}"
|
114
|
+
else
|
115
|
+
"#{titlecase(path_basename)} #{pluralize(file_pattern)}"
|
116
|
+
end.strip
|
117
|
+
end
|
118
|
+
|
119
|
+
def titlecase(string)
|
120
|
+
string = string.to_s
|
121
|
+
"#{string[0..0].upcase}#{string[1..-1]}"
|
122
|
+
end
|
123
|
+
|
124
|
+
def pluralize(string)
|
125
|
+
"#{string}s" unless string.to_s.empty?
|
126
|
+
end
|
25
127
|
|
128
|
+
def path_prefix
|
129
|
+
(defined?(Rails) && Rails.root) || Pathname.pwd
|
26
130
|
end
|
27
131
|
end
|
28
132
|
end
|
data/lib/code_metrics/version.rb
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
require File.expand_path('../boot', __FILE__)
|
2
2
|
|
3
|
-
require 'rails/all'
|
3
|
+
# require 'rails/all'
|
4
|
+
# require "action_controller/railtie"
|
5
|
+
# require "action_mailer/railtie"
|
6
|
+
# require "active_model/railtie"
|
7
|
+
# require "sprockets/railtie"
|
8
|
+
require 'rails/railtie'
|
9
|
+
require "rails/test_unit/railtie"
|
4
10
|
|
5
|
-
Bundler.
|
11
|
+
Bundler.setup
|
6
12
|
require "code_metrics"
|
7
13
|
|
8
14
|
module Dummy
|
@@ -9,21 +9,4 @@ Dummy::Application.configure do
|
|
9
9
|
# Do not eager load code on boot.
|
10
10
|
config.eager_load = false
|
11
11
|
|
12
|
-
# Show full error reports and disable caching.
|
13
|
-
config.consider_all_requests_local = true
|
14
|
-
config.action_controller.perform_caching = false
|
15
|
-
|
16
|
-
# Don't care if the mailer can't send.
|
17
|
-
config.action_mailer.raise_delivery_errors = false
|
18
|
-
|
19
|
-
# Print deprecation notices to the Rails logger.
|
20
|
-
config.active_support.deprecation = :log
|
21
|
-
|
22
|
-
# Raise an error on page load if there are pending migrations
|
23
|
-
config.active_record.migration_error = :page_load
|
24
|
-
|
25
|
-
# Debug mode disables concatenation and preprocessing of assets.
|
26
|
-
# This option may cause significant delays in view rendering with a large
|
27
|
-
# number of complex assets.
|
28
|
-
config.assets.debug = true
|
29
12
|
end
|
@@ -10,38 +10,6 @@ Dummy::Application.configure do
|
|
10
10
|
# Rake tasks automatically ignore this option for performance.
|
11
11
|
config.eager_load = true
|
12
12
|
|
13
|
-
# Full error reports are disabled and caching is turned on.
|
14
|
-
config.consider_all_requests_local = false
|
15
|
-
config.action_controller.perform_caching = true
|
16
|
-
|
17
|
-
# Enable Rack::Cache to put a simple HTTP cache in front of your application
|
18
|
-
# Add `rack-cache` to your Gemfile before enabling this.
|
19
|
-
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
|
20
|
-
# config.action_dispatch.rack_cache = true
|
21
|
-
|
22
|
-
# Disable Rails's static asset server (Apache or nginx will already do this).
|
23
|
-
config.serve_static_assets = false
|
24
|
-
|
25
|
-
# Compress JavaScripts and CSS.
|
26
|
-
config.assets.js_compressor = :uglifier
|
27
|
-
# config.assets.css_compressor = :sass
|
28
|
-
|
29
|
-
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
30
|
-
config.assets.compile = false
|
31
|
-
|
32
|
-
# Generate digests for assets URLs.
|
33
|
-
config.assets.digest = true
|
34
|
-
|
35
|
-
# Version of your assets, change this if you want to expire all your assets.
|
36
|
-
config.assets.version = '1.0'
|
37
|
-
|
38
|
-
# Specifies the header that your server uses for sending files.
|
39
|
-
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
|
40
|
-
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
41
|
-
|
42
|
-
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
43
|
-
# config.force_ssl = true
|
44
|
-
|
45
13
|
# Set to :debug to see everything in the log.
|
46
14
|
config.log_level = :info
|
47
15
|
|
@@ -69,9 +37,6 @@ Dummy::Application.configure do
|
|
69
37
|
# the I18n.default_locale when a translation can not be found).
|
70
38
|
config.i18n.fallbacks = true
|
71
39
|
|
72
|
-
# Send deprecation notices to registered listeners.
|
73
|
-
config.active_support.deprecation = :notify
|
74
|
-
|
75
40
|
# Disable automatic flushing of the log to improve performance.
|
76
41
|
# config.autoflush_log = false
|
77
42
|
|
@@ -12,28 +12,6 @@ Dummy::Application.configure do
|
|
12
12
|
# preloads Rails for running tests, you may have to set it to true.
|
13
13
|
config.eager_load = false
|
14
14
|
|
15
|
-
# Configure static asset server for tests with Cache-Control for performance.
|
16
|
-
config.serve_static_assets = true
|
17
|
-
config.static_cache_control = "public, max-age=3600"
|
18
|
-
|
19
|
-
# Show full error reports and disable caching.
|
20
|
-
config.consider_all_requests_local = true
|
21
|
-
config.action_controller.perform_caching = false
|
22
|
-
|
23
|
-
# Raise exceptions instead of rendering exception templates.
|
24
|
-
config.action_dispatch.show_exceptions = false
|
25
|
-
|
26
|
-
# Disable request forgery protection in test environment.
|
27
|
-
config.action_controller.allow_forgery_protection = false
|
28
|
-
|
29
|
-
# Tell Action Mailer not to deliver emails to the real world.
|
30
|
-
# The :test delivery method accumulates sent emails in the
|
31
|
-
# ActionMailer::Base.deliveries array.
|
32
|
-
config.action_mailer.delivery_method = :test
|
33
|
-
|
34
|
-
# Print deprecation notices to the stderr.
|
35
|
-
config.active_support.deprecation = :stderr
|
36
|
-
|
37
15
|
config.log_level = :fatal
|
38
16
|
config.logger = Logger.new("/dev/null")
|
39
17
|
|
metadata
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code_metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- David Heinemeier Hansson
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-
|
12
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rails
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- - '>'
|
19
|
+
- - ! '>'
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '3.0'
|
20
22
|
- - <
|
@@ -23,27 +25,14 @@ dependencies:
|
|
23
25
|
type: :development
|
24
26
|
prerelease: false
|
25
27
|
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
26
29
|
requirements:
|
27
|
-
- - '>'
|
30
|
+
- - ! '>'
|
28
31
|
- !ruby/object:Gem::Version
|
29
32
|
version: '3.0'
|
30
33
|
- - <
|
31
34
|
- !ruby/object:Gem::Version
|
32
35
|
version: '5.0'
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: sqlite3
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - '>='
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '0'
|
40
|
-
type: :development
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - '>='
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '0'
|
47
36
|
description: rake stats is great for looking at statistics on your code, displaying
|
48
37
|
things like KLOCs (thousands of lines of code) and your code to test ratio.
|
49
38
|
email: david@loudthinking.com
|
@@ -106,26 +95,27 @@ files:
|
|
106
95
|
homepage: https://github.com/bf4/code_metrics
|
107
96
|
licenses:
|
108
97
|
- MIT
|
109
|
-
metadata: {}
|
110
98
|
post_install_message:
|
111
99
|
rdoc_options: []
|
112
100
|
require_paths:
|
113
101
|
- lib
|
114
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
115
104
|
requirements:
|
116
|
-
- - '>='
|
105
|
+
- - ! '>='
|
117
106
|
- !ruby/object:Gem::Version
|
118
107
|
version: 1.9.3
|
119
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
120
110
|
requirements:
|
121
|
-
- - '>='
|
111
|
+
- - ! '>='
|
122
112
|
- !ruby/object:Gem::Version
|
123
113
|
version: 1.8.11
|
124
114
|
requirements: []
|
125
115
|
rubyforge_project:
|
126
|
-
rubygems_version:
|
116
|
+
rubygems_version: 1.8.25
|
127
117
|
signing_key:
|
128
|
-
specification_version:
|
118
|
+
specification_version: 3
|
129
119
|
summary: Extraction of the rails rake stats task as a gem and rails plugin
|
130
120
|
test_files:
|
131
121
|
- test/code_metrics_test.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 4d6b9825dfbdc3ac0a8c0ccd8d6663e52cf6f34e
|
4
|
-
data.tar.gz: 1b084c6d626bbcc7d70d5fc61b34f4d597b6f5b0
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: ad72309b4ce37ddfda8018763fb07858cc589486f7453cccef7b132cea04478df93646da21fa97225a7b40aa40425f675baf004402b00b61baf67d3fb37abb5e
|
7
|
-
data.tar.gz: 32fd57c33546ca5e14260167932f4f69ace5914213f315d88b8a2e2375879f787558b142134856687f5dd8b61123a42dd30ff08213b3f7aa068fd0d550ea442e
|