snip_snip 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +22 -0
- data/Rakefile +29 -0
- data/lib/snip_snip.rb +14 -0
- data/lib/snip_snip/filter.rb +26 -0
- data/lib/snip_snip/railtie.rb +15 -0
- data/lib/snip_snip/registry.rb +33 -0
- data/lib/snip_snip/reporter.rb +44 -0
- data/lib/snip_snip/version.rb +4 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1db377244c92bb3ad11cd32325360adae82845f4
|
4
|
+
data.tar.gz: e3c3d7ff1afcdc0df5de5b13bd599d6004f82351
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e9b20a7fe43cd61f7532a6ea81a71b6d9b42370cc103c5366668fa10e5573a374d9dd595bfa0b149fd5ed67f1ab410c1aadce8fed8081551b38c6d0d22149eb4
|
7
|
+
data.tar.gz: 03d5eaac57e21cb5c0f48de1423ad332791756d2b3ae3eac3935cd86267d60a35f23a5d327abecbfbfa9392b8238ca92280d94eaf369408f499e0681acf67847
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Kevin Deisz
|
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,22 @@
|
|
1
|
+
# SnipSnip
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/kddeisz/snip_snip.svg?branch=master)](https://travis-ci.org/kddeisz/snip_snip)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/kddeisz/snip_snip/badge.svg?branch=master)](https://coveralls.io/github/kddeisz/snip_snip?branch=master)
|
5
|
+
|
6
|
+
SnipSnip tells you what you selected that you shouldn't have in a Rails controller action.
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
Add `SnipSnip` to your Gemfile:
|
11
|
+
|
12
|
+
$ gem 'snip_snip', group: %i[test development]
|
13
|
+
|
14
|
+
Open `snip-snip.log`:
|
15
|
+
|
16
|
+
$ tail -f log/snip-snip.log
|
17
|
+
|
18
|
+
Hit a controller action and see the output.
|
19
|
+
|
20
|
+
## License
|
21
|
+
|
22
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
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
|
+
|
8
|
+
require 'rdoc/task'
|
9
|
+
|
10
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
11
|
+
rdoc.rdoc_dir = 'rdoc'
|
12
|
+
rdoc.title = 'SnipSnip'
|
13
|
+
rdoc.options << '--line-numbers'
|
14
|
+
rdoc.rdoc_files.include('README.md')
|
15
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'bundler/gem_tasks'
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
|
22
|
+
Rake::TestTask.new(:test) do |t|
|
23
|
+
t.libs << 'lib'
|
24
|
+
t.libs << 'test'
|
25
|
+
t.pattern = 'test/**/*_test.rb'
|
26
|
+
t.verbose = false
|
27
|
+
end
|
28
|
+
|
29
|
+
task default: :test
|
data/lib/snip_snip.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'forwardable'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
require 'snip_snip/filter'
|
6
|
+
require 'snip_snip/railtie'
|
7
|
+
require 'snip_snip/registry'
|
8
|
+
require 'snip_snip/reporter'
|
9
|
+
|
10
|
+
module SnipSnip
|
11
|
+
def self.logger
|
12
|
+
@logger ||= Logger.new(Rails.root.join('log', 'snip-snip.log'))
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module SnipSnip
|
3
|
+
class Filter
|
4
|
+
|
5
|
+
attr_accessor :filtered
|
6
|
+
|
7
|
+
def initialize(filtered = [])
|
8
|
+
filtered << ActiveRecord::InternalMetadata if ActiveRecord.const_defined?(:InternalMetadata)
|
9
|
+
self.filtered = filtered
|
10
|
+
end
|
11
|
+
|
12
|
+
def filtered?(record)
|
13
|
+
filtered.any? { |filter| record.is_a?(filter) }
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def filtered?(record)
|
18
|
+
instance.filtered?(record)
|
19
|
+
end
|
20
|
+
|
21
|
+
def instance
|
22
|
+
@instance ||= new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module SnipSnip
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
|
5
|
+
initializer 'snip_snip.load_extensions' do
|
6
|
+
ActiveSupport.on_load(:action_controller) do
|
7
|
+
after_action { Reporter.report(self) }
|
8
|
+
end
|
9
|
+
|
10
|
+
ActiveSupport.on_load(:active_record) do
|
11
|
+
after_find { Registry.register(self) unless Filter.filtered?(self) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module SnipSnip
|
3
|
+
class Registry
|
4
|
+
|
5
|
+
attr_accessor :records
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
clear
|
9
|
+
end
|
10
|
+
|
11
|
+
def clear
|
12
|
+
self.records = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def each_record(&block)
|
16
|
+
return to_enum(:each_record) unless block_given?
|
17
|
+
records.each(&block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def register(record)
|
21
|
+
records << record
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
extend Forwardable
|
26
|
+
def_delegators :instance, :clear, :each_record, :register
|
27
|
+
|
28
|
+
def instance
|
29
|
+
@instance ||= new
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module SnipSnip
|
3
|
+
class Reporter
|
4
|
+
Result = Struct.new(:class_name, :primary_key, :unused) do
|
5
|
+
def report
|
6
|
+
@report ||= "#{class_name} #{primary_key}: #{unused.sort.join(', ')}"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_accessor :results
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
self.results = find_results
|
14
|
+
end
|
15
|
+
|
16
|
+
def report(controller)
|
17
|
+
return if results.empty?
|
18
|
+
|
19
|
+
SnipSnip.logger.info("#{controller.controller_name}##{controller.action_name}")
|
20
|
+
results.sort_by(&:report).each do |result|
|
21
|
+
SnipSnip.logger.info(" #{result.report}")
|
22
|
+
end
|
23
|
+
ensure
|
24
|
+
Registry.clear
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.report(controller)
|
28
|
+
new.report(controller)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def find_results
|
34
|
+
Registry.each_record.each_with_object([]) do |record, records|
|
35
|
+
accessed = record.accessed_fields
|
36
|
+
unused = (record.attributes.keys - accessed)
|
37
|
+
next if unused.empty?
|
38
|
+
|
39
|
+
primary_key = record.class.primary_key
|
40
|
+
records << Result.new(record.class.name, record.send(primary_key), unused)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: snip_snip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Deisz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.0.0.beta4
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.1'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 5.0.0.beta4
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.1'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: coveralls
|
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
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rubocop
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: simplecov
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: sqlite3
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
description: Lets you know what you selected that you shouldn't have
|
90
|
+
email:
|
91
|
+
- kevin.deisz@gmail.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- MIT-LICENSE
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- lib/snip_snip.rb
|
100
|
+
- lib/snip_snip/filter.rb
|
101
|
+
- lib/snip_snip/railtie.rb
|
102
|
+
- lib/snip_snip/registry.rb
|
103
|
+
- lib/snip_snip/reporter.rb
|
104
|
+
- lib/snip_snip/version.rb
|
105
|
+
homepage: https://github.com/kddeisz/snip_snip
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.5.1
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: SnipSnip cuts the deadweight
|
129
|
+
test_files: []
|