gem-tldr 1.0

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -0,0 +1,8 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ Autotest.add_hook :initialize do |at|
6
+ at.testlib = 'minitest/autorun'
7
+ end
8
+
File without changes
@@ -0,0 +1,5 @@
1
+ === 1.0 / 2011-02-25
2
+
3
+ * Major enhancements
4
+ * Birthday!
5
+
@@ -0,0 +1,8 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ lib/rubygems/commands/tldr_command.rb
7
+ lib/rubygems_plugin.rb
8
+ test/test_gem_commands_tldr_command.rb
@@ -0,0 +1,74 @@
1
+ = gem-tldr
2
+
3
+ * https://github.com/drbrain/gem-tldr
4
+
5
+ == DESCRIPTION:
6
+
7
+ Are your gems taking up too much disk space? Documentation got you down?
8
+ Comments stuck in your craw? Tests taking too much space? Fix all that by
9
+ with <tt>gem tldr</tt>.
10
+
11
+ I know that disk space is at a premium these days with an introductory netbook
12
+ or a small AWS EC2 instance containing a mere 160GB. <tt>gem tldr</tt>
13
+ removes the test directory, build artifacts like .c and .h files, comments in
14
+ your ruby source files and comments in your ruby source.
15
+
16
+ == FEATURES/PROBLEMS:
17
+
18
+ * May destroy strings with embedded # characters
19
+ * There's no way to know something is broken as tests have been deleted
20
+
21
+ == SYNOPSIS:
22
+
23
+ gem tldr
24
+
25
+ If you don't want the TL;DR you can provide -V.
26
+
27
+ If you want to see what <tt>gem tldr</tt> would do to your installed gems
28
+ provide <tt>--dry-run</tt>.
29
+
30
+ You can restore your installed gems through
31
+
32
+ gem pristine
33
+
34
+ == REQUIREMENTS:
35
+
36
+ * Fearlessness
37
+
38
+ == INSTALL:
39
+
40
+ Don't
41
+
42
+ == DEVELOPERS:
43
+
44
+ After checking out the source, run:
45
+
46
+ $ rake newb
47
+
48
+ This task will install any missing dependencies, run the tests/specs,
49
+ and generate the RDoc.
50
+
51
+ == LICENSE:
52
+
53
+ (The MIT License)
54
+
55
+ Copyright (c) 2011 Eric Hodel
56
+
57
+ Permission is hereby granted, free of charge, to any person obtaining
58
+ a copy of this software and associated documentation files (the
59
+ 'Software'), to deal in the Software without restriction, including
60
+ without limitation the rights to use, copy, modify, merge, publish,
61
+ distribute, sublicense, and/or sell copies of the Software, and to
62
+ permit persons to whom the Software is furnished to do so, subject to
63
+ the following conditions:
64
+
65
+ The above copyright notice and this permission notice shall be
66
+ included in all copies or substantial portions of the Software.
67
+
68
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
69
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
70
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
71
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
72
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
73
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
74
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.plugin :minitest
7
+ Hoe.plugin :git
8
+
9
+ Hoe.spec 'gem-tldr' do
10
+ developer 'Eric Hodel', 'drbrain@segment7.net'
11
+
12
+ rdoc_locations << 'docs.seattlerb.org:/data/www/docs.seattlerb.org/gem-tldr'
13
+ end
14
+
15
+ # vim: syntax=ruby
@@ -0,0 +1,148 @@
1
+ require 'fileutils'
2
+ require 'find'
3
+ require 'rubygems/command'
4
+
5
+ ##
6
+ # TL;DR your gems with <tt>gem tldr</tt>
7
+
8
+ class Gem::Commands::TldrCommand < Gem::Command
9
+
10
+ VERSION = '1.0'
11
+
12
+ def initialize
13
+ super 'tldr', 'Documentation? Tests? They use too much disk space!'
14
+
15
+ add_option '--dry-run', "don't do anything" do |value, options|
16
+ options[:dry_run] = true
17
+ end
18
+ end
19
+
20
+ def usage # :nodoc:
21
+ program_name
22
+ end
23
+
24
+ def execute
25
+ @verbose = Gem.configuration.really_verbose
26
+
27
+ if @verbose then
28
+ if options[:dry_run] then
29
+ extend FileUtils::DryRun
30
+ else
31
+ extend FileUtils::Verbose
32
+ end
33
+ elsif options[:dry_run] then
34
+ extend FileUtils::NoWrite
35
+ else
36
+ extend FileUtils
37
+ end
38
+
39
+ beginning_size = total_size
40
+
41
+ Gem.source_index.each do |name, spec|
42
+ say "TL;DR #{name}"
43
+ Dir.chdir spec.full_gem_path do
44
+ remove_tests spec
45
+ remove_built_documentation spec
46
+ remove_build_artifacts spec
47
+ remove_file_comments spec
48
+ end
49
+ end
50
+
51
+ ending_size = total_size
52
+
53
+ saved = beginning_size - ending_size
54
+
55
+ say "start: #{beginning_size}B end: #{ending_size}B saved: #{saved}B"
56
+ end
57
+
58
+ ##
59
+ # Find the total size of your Gem path directories
60
+
61
+ def total_size
62
+ size = 0
63
+
64
+ Gem.path.each do |directory|
65
+ Find.find directory do |path|
66
+ stat = File.stat path
67
+ next unless stat.file?
68
+ size += stat.size
69
+ end
70
+ end
71
+
72
+ size
73
+ end
74
+
75
+ ##
76
+ # Remove the documentation for +spec+
77
+
78
+ def remove_built_documentation spec
79
+ doc_dir = File.join spec.installation_path, 'doc', spec.full_name
80
+
81
+ say "\tRemoving built documentation" if @verbose
82
+ rm_rf doc_dir
83
+ end
84
+
85
+ ##
86
+ # Remove build artifacts for C extensions from +spec+
87
+
88
+ def remove_build_artifacts spec
89
+ spec.extensions.each do |extension|
90
+ next unless extension =~ /extconf\.rb$/
91
+ extension_dir = File.dirname extension
92
+
93
+ say "\tRemoving build artifacts in #{extension_dir}" if @verbose
94
+
95
+ Dir["#{extension_dir}/**/*.{c,h,java,o}"].each do |artifact|
96
+ rm_f artifact
97
+ end
98
+
99
+ Dir["#{extension_dir}/**/*.dSYM"].each do |artifact|
100
+ rm_rf artifact
101
+ end
102
+
103
+ rm_f File.join(extension_dir, 'Makefile')
104
+ rm_f File.join(extension_dir, 'extconf.rb')
105
+ rm_f File.join(extension_dir, 'mkmf.log')
106
+ end
107
+ end
108
+
109
+ ##
110
+ # Remove comments in the ruby files of +spec+
111
+
112
+ def remove_file_comments spec
113
+ say "\tStripping comments" if @verbose
114
+ return if options[:dry_run]
115
+ spec.require_paths.each do |path|
116
+ Dir["#{path}/**/*.rb"].each do |file|
117
+ ruby = File.read file
118
+
119
+ stripped = strip_comments ruby
120
+
121
+ open file, 'w' do |io|
122
+ io.write stripped
123
+ end
124
+ end
125
+ end
126
+ end
127
+
128
+ ##
129
+ # Remove the tests (and specs) of +spec+
130
+
131
+ def remove_tests spec
132
+ say "\tRemoving tests" if @verbose
133
+ Dir['{test,spec}'].each do |dir|
134
+ rm_rf dir
135
+ end
136
+ end
137
+
138
+ ##
139
+ # Strips comments out of +ruby+. Destructive!
140
+
141
+ def strip_comments ruby
142
+ ruby.gsub!(/^[ \t]*#[^{@$].*?\r?\n/, '')
143
+ ruby.gsub!(/[ \t]*#[^{@$].*?$/, '')
144
+ ruby
145
+ end
146
+
147
+ end
148
+
@@ -0,0 +1,4 @@
1
+ require 'rubygems/command_manager'
2
+
3
+ Gem::CommandManager.instance.register_command :tldr
4
+
@@ -0,0 +1,41 @@
1
+ require 'rubygems/test_case'
2
+ require 'rubygems/commands/tldr_command'
3
+
4
+ class TestGemCommandsTldrCommand < Gem::TestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @cmd = Gem::Commands::TldrCommand.new
10
+ end
11
+
12
+ def test_strip_comments
13
+ ruby = <<-'RUBY'
14
+ # comment for C
15
+ class C
16
+
17
+ # comment for m
18
+ def m # :yields: something
19
+ puts "hello #{world}"
20
+ end
21
+
22
+ end
23
+ RUBY
24
+
25
+ @cmd.strip_comments ruby
26
+
27
+ expected = <<-'EXPECTED'
28
+ class C
29
+
30
+ def m
31
+ puts "hello #{world}"
32
+ end
33
+
34
+ end
35
+ EXPECTED
36
+
37
+ assert_equal expected, ruby
38
+ end
39
+
40
+ end
41
+
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem-tldr
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ version: "1.0"
10
+ platform: ruby
11
+ authors:
12
+ - Eric Hodel
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain:
16
+ - |
17
+ -----BEGIN CERTIFICATE-----
18
+ MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy
19
+ YWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZFgNu
20
+ ZXQwHhcNMDcxMjIxMDIwNDE0WhcNMDgxMjIwMDIwNDE0WjBBMRAwDgYDVQQDDAdk
21
+ cmJyYWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZ
22
+ FgNuZXQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCbbgLrGLGIDE76
23
+ LV/cvxdEzCuYuS3oG9PrSZnuDweySUfdp/so0cDq+j8bqy6OzZSw07gdjwFMSd6J
24
+ U5ddZCVywn5nnAQ+Ui7jMW54CYt5/H6f2US6U0hQOjJR6cpfiymgxGdfyTiVcvTm
25
+ Gj/okWrQl0NjYOYBpDi+9PPmaH2RmLJu0dB/NylsDnW5j6yN1BEI8MfJRR+HRKZY
26
+ mUtgzBwF1V4KIZQ8EuL6I/nHVu07i6IkrpAgxpXUfdJQJi0oZAqXurAV3yTxkFwd
27
+ g62YrrW26mDe+pZBzR6bpLE+PmXCzz7UxUq3AE0gPHbiMXie3EFE0oxnsU3lIduh
28
+ sCANiQ8BAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
29
+ BBS5k4Z75VSpdM0AclG2UvzFA/VW5DANBgkqhkiG9w0BAQUFAAOCAQEAHagT4lfX
30
+ kP/hDaiwGct7XPuVGbrOsKRVD59FF5kETBxEc9UQ1clKWngf8JoVuEoKD774dW19
31
+ bU0GOVWO+J6FMmT/Cp7nuFJ79egMf/gy4gfUfQMuvfcr6DvZUPIs9P/TlK59iMYF
32
+ DIOQ3DxdF3rMzztNUCizN4taVscEsjCcgW6WkUJnGdqlu3OHWpQxZBJkBTjPCoc6
33
+ UW6on70SFPmAy/5Cq0OJNGEWBfgD9q7rrs/X8GGwUWqXb85RXnUVi/P8Up75E0ag
34
+ 14jEc90kN+C7oI/AGCBN0j6JnEtYIEJZibjjDJTSMWlUKKkj30kq7hlUC2CepJ4v
35
+ x52qPcexcYZR7w==
36
+ -----END CERTIFICATE-----
37
+
38
+ date: 2011-02-25 00:00:00 -08:00
39
+ default_executable:
40
+ dependencies:
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ prerelease: false
44
+ requirement: &id001 !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 11
50
+ segments:
51
+ - 2
52
+ - 0
53
+ - 2
54
+ version: 2.0.2
55
+ type: :development
56
+ version_requirements: *id001
57
+ - !ruby/object:Gem::Dependency
58
+ name: hoe
59
+ prerelease: false
60
+ requirement: &id002 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 43
66
+ segments:
67
+ - 2
68
+ - 9
69
+ - 0
70
+ version: 2.9.0
71
+ type: :development
72
+ version_requirements: *id002
73
+ description: |-
74
+ Are your gems taking up too much disk space? Documentation got you down?
75
+ Comments stuck in your craw? Tests taking too much space? Fix all that by
76
+ with <tt>gem tldr</tt>.
77
+
78
+ I know that disk space is at a premium these days with an introductory netbook
79
+ or a small AWS EC2 instance containing a mere 160GB. <tt>gem tldr</tt>
80
+ removes the test directory, build artifacts like .c and .h files, comments in
81
+ your ruby source files and comments in your ruby source.
82
+ email:
83
+ - drbrain@segment7.net
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files:
89
+ - History.txt
90
+ - Manifest.txt
91
+ - README.txt
92
+ files:
93
+ - .autotest
94
+ - History.txt
95
+ - Manifest.txt
96
+ - README.txt
97
+ - Rakefile
98
+ - lib/rubygems/commands/tldr_command.rb
99
+ - lib/rubygems_plugin.rb
100
+ - test/test_gem_commands_tldr_command.rb
101
+ - .gemtest
102
+ has_rdoc: true
103
+ homepage: https://github.com/drbrain/gem-tldr
104
+ licenses: []
105
+
106
+ post_install_message:
107
+ rdoc_options:
108
+ - --main
109
+ - README.txt
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ requirements: []
131
+
132
+ rubyforge_project: gem-tldr
133
+ rubygems_version: 1.5.2
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: Are your gems taking up too much disk space? Documentation got you down? Comments stuck in your craw? Tests taking too much space? Fix all that by with <tt>gem tldr</tt>
137
+ test_files:
138
+ - test/test_gem_commands_tldr_command.rb
@@ -0,0 +1 @@
1
+ tܥ��PFfPy� ~k�|�$�������g�ë��LzX���W���y���J��1�̡�r�x1{�� 5�Y�唑�%߽�1�oXJƕ�. ��n�1�V