flatfoot 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3d57461b108074affbadb916fb50a09dc2fef727
4
+ data.tar.gz: 0a617de4b97841e52f1fa18116a3c2cb2770ffcd
5
+ SHA512:
6
+ metadata.gz: 23e379745fe8d6defe7c3519c9294889453bb775f268d0556402ca9b6867438dddf1a61a29e315033778c0a94e7f6ad21bb793438d4f1096bf97e2e39bd35f6f
7
+ data.tar.gz: 470ab69f4bb373f6501801e313fc7a83ebe8abd4546afc2b3672a095fca27e2c4e2be24716b9890c713295897147ba3c77d1d8e983dbe4fd5c6c51f400c551ec
data/README.md CHANGED
@@ -52,6 +52,24 @@ Then you should have tasks to help view the flatfoot data
52
52
  rake flatfoot:unused # report unused views
53
53
  rake flatfoot:used # report used views
54
54
 
55
+ ### Customising Targets
56
+
57
+ Flatfoot default lookup is `app/views/**/*.html.erb` rejecting all mailer views.
58
+ This will cover many apps but sometimes your project has different characteristics as:
59
+ - using other view markup language as Haml;
60
+ - using different folder structure (engines, for example), or;
61
+ - you want to analyze parts of your app (/admin, for example).
62
+
63
+ The only change you need in your initialize is define your target during tracker
64
+ initialization as example below:
65
+
66
+ ```ruby
67
+ target = Dir.glob("app/views/admin/**/*.html.haml").reject do |file|
68
+ file.match(/(_mailer)/)
69
+ end
70
+ FLATFOOT = Flatfoot::Tracker.new(Redis.new, options: { target: target })
71
+ ```
72
+
55
73
  ## Contributing
56
74
 
57
75
  1. Fork it
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "mocha", "~> 0.14.0"
24
24
  spec.add_development_dependency "shoulda"
25
+ spec.add_development_dependency "test-unit"
25
26
  spec.add_development_dependency "rack"
26
27
  spec.add_development_dependency "simplecov"
27
28
  end
@@ -2,17 +2,19 @@ require "flatfoot/version"
2
2
  require 'timeout'
3
3
 
4
4
  module Flatfoot
5
-
5
+
6
6
  class Tracker
7
7
 
8
- attr_accessor :store, :logged_views, :roots
8
+ DEFAULT_TARGET = Dir.glob('app/views/**/*.html.erb').reject{ |file| file.match(/(_mailer)/) }
9
+ attr_accessor :store, :target, :logged_views, :roots
9
10
 
10
11
  def initialize(store, options = {})
11
12
  @store = store
13
+ @target = options[:target] || DEFAULT_TARGET
12
14
  @logged_views = []
13
15
  @roots = options.fetch(:roots){ "#{Rails.root.to_s}/" }.split(',')
14
16
  end
15
-
17
+
16
18
  def track_views(name, start, finish, id, payload)
17
19
  begin
18
20
  if file = payload[:identifier]
@@ -42,18 +44,17 @@ module Flatfoot
42
44
  views = store.smembers(tracker_key)
43
45
  normalized_views = []
44
46
  views.each do |view|
45
- roots.each do |root|
46
- view = view.gsub(/#{root}/,'')
47
- end
48
- normalized_views << view
49
- end
47
+ roots.each do |root|
48
+ view = view.gsub(/#{root}/,'')
49
+ end
50
+ normalized_views << view
51
+ end
50
52
  normalized_views
51
53
  end
52
54
 
53
55
  def unused_views
54
- all_views = Dir.glob('app/views/**/*.html.erb').reject{|file| file.match(/(_mailer)/)}
55
56
  recently_used_views = used_views
56
- all_views = all_views.reject{ |view| recently_used_views.include?(view) }
57
+ all_views = target.reject{ |view| recently_used_views.include?(view) }
57
58
  # since layouts don't include format we count them used if they match with ANY formats
58
59
  all_views = all_views.reject{ |view| view.match(/\/layouts\//) && recently_used_views.any?{|used_view| view.include?(used_view)} }
59
60
  end
@@ -1,3 +1,3 @@
1
1
  module Flatfoot
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -6,6 +6,7 @@ class ReporterTest < Test::Unit::TestCase
6
6
  tracker = Flatfoot::Tracker.new("store", {:roots => 'dir'})
7
7
  assert_equal 'dir', tracker.roots.first
8
8
  assert_equal 'store', tracker.store
9
+ assert_equal [], tracker.target
9
10
  assert_equal [], tracker.logged_views
10
11
  end
11
12
 
@@ -34,8 +35,8 @@ class ReporterTest < Test::Unit::TestCase
34
35
 
35
36
  should "report unused partials" do
36
37
  store = fake_store
37
- Dir.expects(:glob).returns(['file', 'not_used'])
38
- tracker = Flatfoot::Tracker.new(store, {:roots => 'dir'})
38
+ target = ['file', 'not_used']
39
+ tracker = Flatfoot::Tracker.new(store, {:roots => 'dir', :target => target})
39
40
  tracker.track_views('name', 'start', 'finish', 'id', {:identifier => 'file'})
40
41
  assert_equal ['not_used'], tracker.unused_views
41
42
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flatfoot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Dan Mayer
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-05-12 00:00:00.000000000 Z
11
+ date: 2015-01-11 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,23 +27,20 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: mocha
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,49 +55,57 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: shoulda
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
76
81
  - !ruby/object:Gem::Version
77
82
  version: '0'
78
83
  - !ruby/object:Gem::Dependency
79
84
  name: rack
80
85
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
86
  requirements:
83
- - - ! '>='
87
+ - - '>='
84
88
  - !ruby/object:Gem::Version
85
89
  version: '0'
86
90
  type: :development
87
91
  prerelease: false
88
92
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
93
  requirements:
91
- - - ! '>='
94
+ - - '>='
92
95
  - !ruby/object:Gem::Version
93
96
  version: '0'
94
97
  - !ruby/object:Gem::Dependency
95
98
  name: simplecov
96
99
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
100
  requirements:
99
- - - ! '>='
101
+ - - '>='
100
102
  - !ruby/object:Gem::Version
101
103
  version: '0'
102
104
  type: :development
103
105
  prerelease: false
104
106
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
107
  requirements:
107
- - - ! '>='
108
+ - - '>='
108
109
  - !ruby/object:Gem::Version
109
110
  version: '0'
110
111
  description: Discover dead view files in your app. Track view layer render usage
@@ -128,33 +129,26 @@ files:
128
129
  homepage: ''
129
130
  licenses:
130
131
  - MIT
132
+ metadata: {}
131
133
  post_install_message:
132
134
  rdoc_options: []
133
135
  require_paths:
134
136
  - lib
135
137
  required_ruby_version: !ruby/object:Gem::Requirement
136
- none: false
137
138
  requirements:
138
- - - ! '>='
139
+ - - '>='
139
140
  - !ruby/object:Gem::Version
140
141
  version: '0'
141
- segments:
142
- - 0
143
- hash: -445969606613763391
144
142
  required_rubygems_version: !ruby/object:Gem::Requirement
145
- none: false
146
143
  requirements:
147
- - - ! '>='
144
+ - - '>='
148
145
  - !ruby/object:Gem::Version
149
146
  version: '0'
150
- segments:
151
- - 0
152
- hash: -445969606613763391
153
147
  requirements: []
154
148
  rubyforge_project:
155
- rubygems_version: 1.8.23
149
+ rubygems_version: 2.0.3
156
150
  signing_key:
157
- specification_version: 3
151
+ specification_version: 4
158
152
  summary: Discover dead view files in your app. Track view layer render usage
159
153
  test_files:
160
154
  - test/test_helper.rb