flatfoot 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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/flatfoot.gemspec +23 -0
- data/lib/flatfoot/version.rb +3 -0
- data/lib/flatfoot.rb +68 -0
- metadata +92 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Dan Mayer
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Flatfoot
|
2
|
+
|
3
|
+
[Flatfoot is a synonym for tracker](http://thesaurus.com/browse/tracker). As the name RenderTracker seemed generic, and gumshoe my favorite was taken.
|
4
|
+
|
5
|
+
This gem will help you track unused views in your application.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'flatfoot'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install flatfoot
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
To use this gem, just initialize it in some initializer like `config/initializers/notifications.rb`
|
24
|
+
|
25
|
+
then create an instance and subscribe it to `ActiveSupport::Notifications` events.
|
26
|
+
|
27
|
+
FLATFOOT = Flatfoot::Tracker.new(Redis.new)
|
28
|
+
|
29
|
+
ActiveSupport::Notifications.subscribe /render_partial.action_view|render_template.action_view/ do |name, start, finish, id, payload|
|
30
|
+
FLATFOOT.track_views(name, start, finish, id, payload) unless name.include?('!')
|
31
|
+
end
|
32
|
+
|
33
|
+
Start up your app and then in console you can check used views or unused views
|
34
|
+
|
35
|
+
FLATFOOT.used_views
|
36
|
+
=> ["app/views/layouts/_old_layout.html.erb",...
|
37
|
+
|
38
|
+
FLATFOOT.unused_views
|
39
|
+
=> ["app/views/something/_old_partial.html.erb",...
|
40
|
+
|
41
|
+
After making changes deploying or just to clear out the Redis size you can clear the saved data.
|
42
|
+
|
43
|
+
FLATFOOT.reset_recordings
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/flatfoot.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'flatfoot/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "flatfoot"
|
8
|
+
spec.version = Flatfoot::VERSION
|
9
|
+
spec.authors = ["Dan Mayer"]
|
10
|
+
spec.email = ["dan.mayer@livingsocial.com"]
|
11
|
+
spec.description = %q{Discover dead view files in your app. Track view layer render usage}
|
12
|
+
spec.summary = %q{Discover dead view files in your app. Track view layer render usage}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/flatfoot.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require "flatfoot/version"
|
2
|
+
|
3
|
+
module Flatfoot
|
4
|
+
|
5
|
+
class Tracker
|
6
|
+
|
7
|
+
attr_accessor :store, :logged_views, :roots
|
8
|
+
|
9
|
+
def initialize(store, options = {})
|
10
|
+
@store = store
|
11
|
+
@logged_views = []
|
12
|
+
@roots = options.fetch(:roots){ "#{Rails.root.to_s}/" }.split(',')
|
13
|
+
end
|
14
|
+
|
15
|
+
def track_views(name, start, finish, id, payload)
|
16
|
+
if file = payload[:identifier]
|
17
|
+
unless logged_views.include?(file)
|
18
|
+
logged_views << file
|
19
|
+
store.sadd(tracker_key, file)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
###
|
23
|
+
# Annoyingly while you get full path for templates
|
24
|
+
# notifications only pass part of the path for layouts dropping any format info
|
25
|
+
# such as .html.erb or .js.erb
|
26
|
+
# http://edgeguides.rubyonrails.org/active_support_instrumentation.html#render_partial-action_view
|
27
|
+
###
|
28
|
+
if layout_file = payload[:layout]
|
29
|
+
unless logged_views.include?(layout_file)
|
30
|
+
logged_views << layout_file
|
31
|
+
store.sadd(tracker_key, layout_file)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def used_views
|
37
|
+
views = store.smembers(tracker_key)
|
38
|
+
normalized_views = []
|
39
|
+
views.each do |view|
|
40
|
+
roots.each do |root|
|
41
|
+
view = view.gsub(/#{root}/,'')
|
42
|
+
end
|
43
|
+
normalized_views << view
|
44
|
+
end
|
45
|
+
normalized_views
|
46
|
+
end
|
47
|
+
|
48
|
+
def unused_views
|
49
|
+
all_views = Dir.glob('app/views/**/*.html.erb').reject{|file| file.match(/(_mailer)/)}
|
50
|
+
recently_used_views = used_views
|
51
|
+
all_views = all_views.reject{ |view| recently_used_views.include?(view) }
|
52
|
+
# since layouts don't include format we count them used if they match with ANY formats
|
53
|
+
all_views = all_views.reject{ |view| view.match(/\/layouts\//) && recently_used_views.any?{|used_view| view.include?(used_view)} }
|
54
|
+
end
|
55
|
+
|
56
|
+
def reset_recordings
|
57
|
+
store.del(tracker_key)
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def tracker_key
|
63
|
+
'render_tracker'
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flatfoot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Mayer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Discover dead view files in your app. Track view layer render usage
|
47
|
+
email:
|
48
|
+
- dan.mayer@livingsocial.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- flatfoot.gemspec
|
59
|
+
- lib/flatfoot.rb
|
60
|
+
- lib/flatfoot/version.rb
|
61
|
+
homepage: ''
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
hash: -649716077801071903
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
hash: -649716077801071903
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.8.23
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Discover dead view files in your app. Track view layer render usage
|
92
|
+
test_files: []
|