bundle_outdated 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bundle_outdated.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Patrick Lenz
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,57 @@
1
+ # bundle\_outdated
2
+
3
+ ## Description
4
+
5
+ A simple gem to analyze your `Gemfile` and `Gemfile.lock` to find
6
+ out which of the gems in your project have newer versions available
7
+ and thus could potentially be updated.
8
+
9
+ ## Installation
10
+
11
+ $ gem install bundle_outdated
12
+
13
+ ## Usage
14
+
15
+ From your Ruby project directory or your `Rails.root`:
16
+
17
+ $ bundle-outdated
18
+
19
+ ## Example report
20
+
21
+ Finding outdated gems..
22
+
23
+ Newer versions found for:
24
+ mail (2.3.0 > 2.2.18)
25
+ hoptoad_notifier (2.4.9 > 2.3)
26
+ devise (1.3.4 > 1.3.3)
27
+ oa-oauth (0.2.5 > 0.2.4)
28
+ twitter (1.4.1 > 1.4.0)
29
+ kaminari (0.12.4 > 0.12.1)
30
+ meta_search (1.0.5 > 1.0.4)
31
+ paper_trail (2.2.2 > 2)
32
+ jquery-rails (1.0 > 0.2.7)
33
+ guard-rspec (0.3.1 > 0.3.0)
34
+
35
+ Lock bundle to these versions by putting the following in your Gemfile:
36
+ gem 'mail', '2.3.0'
37
+ gem 'hoptoad_notifier', '2.4.9'
38
+ gem 'devise', '1.3.4'
39
+ gem 'oa-oauth', '0.2.5'
40
+ gem 'twitter', '1.4.1'
41
+ gem 'kaminari', '0.12.4'
42
+ gem 'meta_search', '1.0.5'
43
+ gem 'paper_trail', '2.2.2'
44
+ gem 'jquery-rails', '1.0'
45
+ gem 'guard-rspec', '0.3.1'
46
+
47
+ You may try to update non-specific dependencies via:
48
+ $ bundle update mail hoptoad_notifier paper_trail
49
+
50
+ Handwaving specifications:
51
+ mail: ~> 2.2.18
52
+ hoptoad_notifier: ~> 2.3
53
+ paper_trail: ~> 2
54
+
55
+ ## License
56
+
57
+ Released under the MIT License. See the LICENSE file for further details.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ require 'rake/testtask'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ Rake::TestTask.new :test do |t|
6
+ t.libs << 'lib'
7
+ t.libs << 'test'
8
+ t.test_files = FileList['test/**/*_test.rb']
9
+ t.verbose = true
10
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ # This allows compass to run easily from a git checkout without install.
3
+ # Credit: Compass [https://github.com/chriseppstein/compass/]
4
+ def fallback_load_path(path)
5
+ retried = false
6
+ begin
7
+ yield
8
+ rescue LoadError
9
+ unless retried
10
+ $: << path
11
+ retried = true
12
+ retry
13
+ end
14
+ raise
15
+ end
16
+ end
17
+
18
+ fallback_load_path(File.join(File.dirname(__FILE__), '..', 'lib')) do
19
+ require 'bundle_outdated'
20
+ end
21
+
22
+ BundleOutdated.search!
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "bundle_outdated/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "bundle_outdated"
7
+ s.version = BundleOutdated::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Patrick Lenz"]
10
+ s.email = ["patricklenz@gmail.com"]
11
+ s.homepage = "https://github.com/scoop/bundle_outdated"
12
+ s.summary = %q{Find out which gems in your bundle are outdated.}
13
+ s.description = %q{Find out which gems in your bundle are outdated.}
14
+
15
+ s.rubyforge_project = "bundle_outdated"
16
+
17
+ s.add_dependency 'rr', '~> 1.0'
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
@@ -0,0 +1,3 @@
1
+ module BundleOutdated
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,97 @@
1
+ module BundleOutdated
2
+ def self.search!
3
+ Searcher.new.search!
4
+ end
5
+
6
+ class GemDependency
7
+ attr_reader :name, :version, :handwaving
8
+
9
+ VERSION_REGEXP = /^(['"])([~><=]*)\s*(.+?)\1$/
10
+ GEMNAME_REGEXP = /gem\s(['"])(.+?)\1/
11
+
12
+ def initialize(gemfile_string)
13
+ self.name, self.version = gemfile_string.split(/,\s*/)
14
+ end
15
+
16
+ def name=(new_name)
17
+ @name = nil
18
+ if new_name && new_name.match(GEMNAME_REGEXP)
19
+ @name = $2
20
+ end
21
+ end
22
+
23
+ def version=(new_version)
24
+ @version = nil
25
+ if new_version && new_version.match(VERSION_REGEXP)
26
+ @handwaving = !$2.empty? && $2
27
+ @version = Gem::Version.new($3)
28
+ end
29
+ end
30
+
31
+ def handwaving?; !!handwaving; end
32
+
33
+ def to_s
34
+ "#{name}, Version: #{ version || 'Any' }"
35
+ end
36
+
37
+ def latest_version
38
+ @latest_version ||= Gem.latest_version_for(name)
39
+ end
40
+
41
+ def outdated?
42
+ return false unless version
43
+ version < latest_version
44
+ end
45
+ end
46
+
47
+ class Searcher
48
+ class GemfileNotFound < StandardError; end
49
+
50
+ def search!
51
+ puts "Finding outdated gems.."
52
+
53
+ unless outdated_gems.empty?
54
+ puts "\nNewer versions found for:"
55
+ outdated_gems.each do |gem|
56
+ puts " #{gem.name} (#{gem.latest_version} > #{gem.version})"
57
+ end
58
+
59
+ puts "\nLock bundle to these versions by putting the following in your Gemfile:"
60
+ outdated_gems.each do |gem|
61
+ puts " gem '#{gem.name}', '#{gem.latest_version}'"
62
+ end
63
+ end
64
+
65
+ unless handwaving_gems.empty?
66
+ puts "\nYou may try to update non-specific dependencies via:"
67
+ puts " $ bundle update #{handwaving_gems.collect(&:name).join(' ')}"
68
+ puts "\nHandwaving specifications:"
69
+ handwaving_gems.collect do |g|
70
+ puts " #{g.name}: #{ [ g.handwaving, g.version ].join(' ') }"
71
+ end
72
+ end
73
+ end
74
+
75
+ def outdated_gems
76
+ @outdated_gems ||= all_gems.find_all(&:outdated?)
77
+ end
78
+
79
+ def handwaving_gems
80
+ @handwaving_gems ||= all_gems.find_all(&:handwaving?)
81
+ end
82
+
83
+ def gemfile
84
+ unless File.exists?('Gemfile')
85
+ raise GemfileNotFound, 'Gemfile not found! Please re-run in your Ruby project directory.'
86
+ end
87
+
88
+ @gemfile ||= File.read('Gemfile').split(/\n/)
89
+ end
90
+
91
+ def all_gems
92
+ @all_gems ||= gemfile.grep(/^\s*gem\b/).collect do |gem|
93
+ GemDependency.new gem
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class BundleOutdatedTest < Test::Unit::TestCase
4
+ def test_truth
5
+ assert true
6
+ end
7
+ end
@@ -0,0 +1,63 @@
1
+ require 'test_helper'
2
+ require 'bundle_outdated'
3
+
4
+ class GemDependencyTest < Test::Unit::TestCase
5
+ def setup
6
+ stub(Gem).latest_version_for('rails') { Gem::Version.new '3.1' }
7
+ end
8
+
9
+ def test_name_cleanup_double_quotes
10
+ gd = BundleOutdated::GemDependency.new 'gem "rails"'
11
+ assert_equal 'rails', gd.name
12
+ end
13
+
14
+ def test_name_cleanup_single_quotes
15
+ gd = BundleOutdated::GemDependency.new "gem 'rails'"
16
+ assert_equal 'rails', gd.name
17
+ end
18
+
19
+ def test_version_cleanup
20
+ gd = BundleOutdated::GemDependency.new 'gem "rails", "3.1"'
21
+ assert_equal '3.1', gd.version.to_s
22
+ end
23
+
24
+ def test_version_garbage_cleanup
25
+ gd = BundleOutdated::GemDependency.new 'gem "rails", :require => "rails"'
26
+ assert_equal '', gd.version.to_s
27
+ end
28
+
29
+ def test_version_garbage_spermy
30
+ gd = BundleOutdated::GemDependency.new 'gem "rails", "~> 3.1"'
31
+ assert_equal '3.1', gd.version.to_s
32
+ end
33
+
34
+ def test_version_with_handwaving
35
+ gd = BundleOutdated::GemDependency.new 'gem "rails", "~> 3.1"'
36
+ assert gd.handwaving?
37
+ end
38
+
39
+ def test_version_without_handwaving
40
+ gd = BundleOutdated::GemDependency.new 'gem "rails", "3.1"'
41
+ assert !gd.handwaving?
42
+ end
43
+
44
+ def test_inspection
45
+ gd = BundleOutdated::GemDependency.new 'gem "rails", "~> 3.1"'
46
+ assert_equal 'rails, Version: 3.1', gd.to_s
47
+ end
48
+
49
+ def test_latest_version
50
+ gd = BundleOutdated::GemDependency.new 'gem "rails"'
51
+ assert_equal '3.1', gd.latest_version.to_s
52
+ end
53
+
54
+ def test_is_outdated
55
+ gd = BundleOutdated::GemDependency.new 'gem "rails", "3.0.7"'
56
+ assert gd.outdated?
57
+ end
58
+
59
+ def test_is_not_outdated
60
+ gd = BundleOutdated::GemDependency.new 'gem "rails", "3.1"'
61
+ assert !gd.outdated?
62
+ end
63
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+ require 'bundle_outdated'
3
+
4
+ class SearcherTest < Test::Unit::TestCase
5
+ def setup
6
+ stub(File).read('Gemfile') { "gem 'rails', '~> 3.0'" }
7
+ stub(Gem).latest_version_for('rails') { Gem::Version.new('3.1') }
8
+ @searcher = BundleOutdated::Searcher.new
9
+ end
10
+
11
+ def test_all_gems_creates_gem_dependencies
12
+ assert_kind_of BundleOutdated::GemDependency, @searcher.all_gems.first
13
+ end
14
+
15
+ def test_all_gems_ignores_lines_without_gem
16
+ mock(File).read('Gemfile') { "source 'gemcutter.org'\ngem 'rails', '~> 3.0'" }
17
+ assert_equal 1, @searcher.all_gems.size
18
+ end
19
+
20
+ def test_gemfile_raises_error_if_no_gemfile_found
21
+ mock(File).exists?('Gemfile') { false }
22
+ assert_raises(BundleOutdated::Searcher::GemfileNotFound) {
23
+ @searcher.gemfile
24
+ }
25
+ end
26
+
27
+ def test_gemfile_reads_and_splits_gemfile
28
+ mock(File).read('Gemfile') { "gem 'rails', '3.0'" }
29
+ assert_equal ["gem 'rails', '3.0'"], @searcher.gemfile
30
+ end
31
+
32
+ def test_search_finds_all_outdated_gems
33
+ assert_equal 'rails', @searcher.outdated_gems.first.name
34
+ end
35
+
36
+ def test_search_finds_all_handwaving_gems
37
+ assert_equal 'rails', @searcher.handwaving_gems.first.name
38
+ end
39
+ end
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'rr'
4
+
5
+ class Test::Unit::TestCase
6
+ include RR::Adapters::TestUnit
7
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bundle_outdated
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Patrick Lenz
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-05 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rr
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 1
31
+ - 0
32
+ version: "1.0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: Find out which gems in your bundle are outdated.
36
+ email:
37
+ - patricklenz@gmail.com
38
+ executables:
39
+ - bundle-outdated
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - LICENSE
48
+ - README.md
49
+ - Rakefile
50
+ - bin/bundle-outdated
51
+ - bundle_outdated.gemspec
52
+ - lib/bundle_outdated.rb
53
+ - lib/bundle_outdated/version.rb
54
+ - test/bundle_outdated_test.rb
55
+ - test/gem_dependency_test.rb
56
+ - test/searcher_test.rb
57
+ - test/test_helper.rb
58
+ homepage: https://github.com/scoop/bundle_outdated
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options: []
63
+
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project: bundle_outdated
87
+ rubygems_version: 1.7.2
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Find out which gems in your bundle are outdated.
91
+ test_files:
92
+ - test/bundle_outdated_test.rb
93
+ - test/gem_dependency_test.rb
94
+ - test/searcher_test.rb
95
+ - test/test_helper.rb