gem-depclean 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Keita Urashima
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.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = gem-depclean
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 Keita Urashima. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "gem-depclean"
8
+ gem.summary = %Q{Uninstall all unnecessary gems.}
9
+ gem.description = %Q{Uninstall all unnecessary gems.}
10
+ gem.email = "ursm@ursm.jp"
11
+ gem.homepage = "http://github.com/ursm/gem-depclean"
12
+ gem.authors = ["Keita Urashima"]
13
+ gem.add_development_dependency "rspec"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ if File.exist?('VERSION')
40
+ version = File.read('VERSION')
41
+ else
42
+ version = ""
43
+ end
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "gem-depclean #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,49 @@
1
+ require 'rubygems/command'
2
+ require 'rubygems/uninstaller'
3
+ require 'set'
4
+
5
+ class Gem::Commands::DepcleanCommand < Gem::Command
6
+ def initialize
7
+ super 'depclean', 'Uninstall all unnecessary gems'
8
+ end
9
+
10
+ def world
11
+ Gem::CommandManager.instance['world']
12
+ end
13
+
14
+ def execute
15
+ gems = world.world_gems.inject(Set.new) {|acc, gem|
16
+ acc + collect_dependencies(gem)
17
+ }
18
+
19
+ targets = (Gem.source_index.map(&:last) - gems.to_a).sort_by(&:name)
20
+
21
+ if targets.empty?
22
+ say 'Your world is already clean.'
23
+ return
24
+ end
25
+
26
+
27
+ targets.each do |t|
28
+ say "#{t.name} (#{t.version})"
29
+ end
30
+
31
+ return unless ask_yes_no 'Would you like to uninstall these gems?'
32
+
33
+ targets.each do |gem|
34
+ Gem::Uninstaller.new(gem.name, :version => gem.version, :ignore => true).uninstall
35
+ end
36
+ end
37
+
38
+ def collect_dependencies(gem, acc = Set.new)
39
+ acc << gem
40
+
41
+ gem.dependencies.map {|dep|
42
+ Gem.source_index.find_name(dep.name, dep.version_requirements).sort_by(&:version).last
43
+ }.compact.reject {|s| acc.include?(s) }.each do |dep|
44
+ collect_dependencies(dep, acc)
45
+ end
46
+
47
+ acc
48
+ end
49
+ end
@@ -0,0 +1,52 @@
1
+ require 'rubygems/command'
2
+ require 'rubygems/requirement'
3
+ require 'yaml'
4
+
5
+ class Gem::Commands::WorldCommand < Gem::Command
6
+ def initialize
7
+ super 'world', 'Display gems that in your world'
8
+
9
+ add_option '--init' do |v, opts|
10
+ opts[:init] = v
11
+ end
12
+ end
13
+
14
+ def execute
15
+ if options[:init]
16
+ init_world
17
+ else
18
+ list
19
+ end
20
+ end
21
+
22
+ def world_path
23
+ File.join(Gem.user_home, '.gem', 'world')
24
+ end
25
+
26
+ def world_gems
27
+ YAML.load_file(world_path).inject([]) {|acc, (name, versions)|
28
+ acc + versions.map {|v|
29
+ Gem.source_index.find_name(name, v).sort_by(&:version).last
30
+ }
31
+ }
32
+ end
33
+
34
+ def list
35
+ YAML.load_file(world_path).sort_by(&:first).each do |name, versions|
36
+ say "#{name} (#{versions.join(', ')})"
37
+ end
38
+ end
39
+
40
+ def init_world
41
+ open(world_path, 'w') do |f|
42
+ f << Gem.source_index.map(&:last).select {|spec|
43
+ spec.dependent_gems.empty?
44
+ }.group_by(&:name).sort_by(&:first).inject({}) {|h, (name, specs)|
45
+ versions = specs.sort_by(&:version).map {|spec| spec.version }
46
+ versions[-1] = Gem::Requirement.default
47
+
48
+ h.merge(name => versions.map(&:to_s))
49
+ }.to_yaml
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems/command_manager'
2
+
3
+ Dir.glob(File.join(File.dirname(__FILE__), 'commands', '*_command.rb')) do |path|
4
+ require "commands/#{File.basename(path)}"
5
+ Gem::CommandManager.instance.register_command File.basename(path, '_command.rb').to_sym
6
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'gem-depclean'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem-depclean
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Keita Urashima
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-13 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Uninstall all unnecessary gems.
26
+ email: ursm@ursm.jp
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/commands/depclean_command.rb
42
+ - lib/commands/world_command.rb
43
+ - lib/rubygems_plugin.rb
44
+ - spec/spec_helper.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/ursm/gem-depclean
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --charset=UTF-8
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.5
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Uninstall all unnecessary gems.
73
+ test_files:
74
+ - spec/spec_helper.rb