controller-usage 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/MIT-LICENSE +20 -0
- data/README.md +15 -0
- data/Rakefile +37 -0
- data/lib/controller-usage.rb +7 -0
- data/lib/controller-usage/config.rb +7 -0
- data/lib/controller-usage/railtie.rb +15 -0
- data/lib/controller-usage/report.rb +27 -0
- data/lib/controller-usage/subscriber.rb +22 -0
- data/lib/controller-usage/tasks.rb +34 -0
- data/lib/controller-usage/version.rb +3 -0
- metadata +72 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Controller Usage
|
2
|
+
|
3
|
+
Track usage of Rails 3.x controller actions and identify unused code.
|
4
|
+
|
5
|
+
## Synopsis
|
6
|
+
|
7
|
+
echo 'gem "controller_usage"' >> Gemfile
|
8
|
+
bundle install
|
9
|
+
rake -T cu
|
10
|
+
|
11
|
+
## Warning
|
12
|
+
|
13
|
+
* Writes one line to `#{RAILS_ROOT}/log/controller-usage.log` for every page hit.
|
14
|
+
* Has not been extensively tested.
|
15
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'ControllerUsage'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib'
|
31
|
+
t.libs << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
task :default => :test
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ControllerUsage
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
|
4
|
+
initializer "controller-usage.initialize" do |app|
|
5
|
+
ActiveSupport.on_load :action_controller do
|
6
|
+
Subscriber.attach
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
rake_tasks do
|
11
|
+
load File.expand_path('../tasks.rb', __FILE__)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ControllerUsage
|
2
|
+
class Report
|
3
|
+
include ControllerUsage::Config
|
4
|
+
|
5
|
+
def available_actions
|
6
|
+
@available_actions ||= begin
|
7
|
+
controllers = Dir[Rails.root.join('app', 'controllers', '*_controller.rb')].map { |filename|
|
8
|
+
File.basename(filename).gsub(/.rb$/, '').camelcase
|
9
|
+
}.uniq.sort
|
10
|
+
|
11
|
+
controllers.map { |controller|
|
12
|
+
controller.constantize.action_methods.reject { |method|
|
13
|
+
method =~ /^_/
|
14
|
+
}.map do |method|
|
15
|
+
"#{controller}##{method}"
|
16
|
+
end
|
17
|
+
}.flatten.sort
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def used_actions
|
22
|
+
@used_actions ||= File.read(log_file).split("\n").map { |line|
|
23
|
+
line.split(' ')[1]
|
24
|
+
}.reject(&:blank?).sort.uniq
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ControllerUsage
|
2
|
+
class Subscriber < ActiveSupport::LogSubscriber
|
3
|
+
include ControllerUsage::Config
|
4
|
+
|
5
|
+
def self.attach
|
6
|
+
attach_to :action_controller
|
7
|
+
end
|
8
|
+
|
9
|
+
def logger
|
10
|
+
@logger ||= ActiveSupport::BufferedLogger.new(log_file)
|
11
|
+
end
|
12
|
+
|
13
|
+
def start_processing event
|
14
|
+
begin
|
15
|
+
payload = event.payload
|
16
|
+
logger.info "#{Time.now.tv_sec} #{payload[:controller]}##{payload[:action]}"
|
17
|
+
rescue => e
|
18
|
+
Rails.logger.warn "ControllerUsage Error: " + e.inspect
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
namespace :cu do
|
2
|
+
|
3
|
+
desc "controllers/actions combinations in this application"
|
4
|
+
task :available do
|
5
|
+
present report.available_actions
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "controllers/actions found in the log file"
|
9
|
+
task :used do
|
10
|
+
present report.used_actions
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "controllers/actions in your application that have not been used"
|
14
|
+
task :unused do
|
15
|
+
present report.available_actions.reject { |action|
|
16
|
+
report.used_actions.include? action
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "controllers/actions found in the log file but not found in your application"
|
21
|
+
task :missing do
|
22
|
+
present report.used_actions.reject { |action|
|
23
|
+
report.available_actions.include? action
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def report
|
28
|
+
@report ||= ControllerUsage::Report.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def present collection
|
32
|
+
puts collection.join("\n")
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: controller-usage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael Pearson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-01 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &70285346405800 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70285346405800
|
25
|
+
description: Track usage of controllers and actions.
|
26
|
+
email:
|
27
|
+
- mipearson@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- lib/controller-usage/config.rb
|
33
|
+
- lib/controller-usage/railtie.rb
|
34
|
+
- lib/controller-usage/report.rb
|
35
|
+
- lib/controller-usage/subscriber.rb
|
36
|
+
- lib/controller-usage/tasks.rb
|
37
|
+
- lib/controller-usage/version.rb
|
38
|
+
- lib/controller-usage.rb
|
39
|
+
- MIT-LICENSE
|
40
|
+
- Rakefile
|
41
|
+
- README.md
|
42
|
+
homepage: http://github.com/mipearson/controller-usage
|
43
|
+
licenses: []
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
hash: 176627699327490862
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
hash: 176627699327490862
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.8.8
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Track usage of controllers and actions.
|
72
|
+
test_files: []
|