update_hints 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.autotest ADDED
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.extra_files << "../some/external/dependency.rb"
7
+ #
8
+ # at.libs << ":../some/external"
9
+ #
10
+ # at.add_exception 'vendor'
11
+ #
12
+ # at.add_mapping(/dependency.rb/) do |f, _|
13
+ # at.files_matching(/test_.*rb$/)
14
+ # end
15
+ #
16
+ # %w(TestA TestB).each do |klass|
17
+ # at.extra_class_map[klass] = "test/test_misc.rb"
18
+ # end
19
+ # end
20
+
21
+ # Autotest.add_hook :run_command do |at|
22
+ # system "rake build"
23
+ # end
data/.gemtest ADDED
File without changes
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2011-05-25
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,8 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ lib/update_hints.rb
7
+ test/sample.xml
8
+ test/test_update_hints.rb
data/README.txt ADDED
@@ -0,0 +1,48 @@
1
+ = update_hints
2
+
3
+ * http://github.com/julik/update_hints
4
+
5
+ == DESCRIPTION:
6
+
7
+ Quickly checks rubygems.org for a new version o a given gem and advises the user on STDERR to install an update
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * Probably some problems with networking if networking fails
12
+
13
+ == SYNOPSIS:
14
+
15
+ UpdateHints.version_check("my_fabulous_gem", MyFabulousGem::VERSION)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * Ruby 1.8.6+
20
+
21
+ == INSTALL:
22
+
23
+ * sudo gem install update_hints
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2011 Julik Tarkhanov
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.spec 'update_hints' do | s |
7
+ s.developer('Julik Tarkhanov', 'me@julik.nl')
8
+ s.extra_dev_deps = {"flexmock" => ">=0"}
9
+ end
10
+
11
+ # vim: syntax=ruby
@@ -0,0 +1,56 @@
1
+ require "net/http"
2
+ require "open-uri"
3
+ require "timeout"
4
+ require "rexml/document"
5
+
6
+ module UpdateHints
7
+ VERSION = '1.0.0'
8
+ GEMCUTTER_URI = "http://rubygems.org/api/v1/gems/%s.xml"
9
+
10
+ # Checks whether rubygems.org has a new version of this specific gem
11
+ # and prints how an update can be obtained if need be.
12
+ # Note: it swallows ANY exception to prevent network-related errors when for some
13
+ # reason the method is run while the app is offline
14
+ def self.version_check(gem_name, present_version_str, destination = $stderr)
15
+ begin
16
+ latest_version = extract_version_from_xml(open(GEMCUTTER_URI % gem_name))
17
+ int_present, int_available = Version.new(present_version_str), Version.new(latest_version)
18
+ if int_available > int_present
19
+ destination << "Your version of #{gem_name} is probably out of date\n"
20
+ destination << "(the current version is #{latest_version}, but you have #{present_version_str}).\n"
21
+ destination << "Please consider updating (run `gem update #{gem_name}`)"
22
+ end
23
+ rescue Exception
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ # For stubbing
30
+ def self.open(*any)
31
+ super
32
+ end
33
+
34
+ #:nodoc:
35
+ class Version
36
+ include Comparable
37
+
38
+ attr_reader :major, :minor, :tiny
39
+ def initialize(version_str)
40
+ @major, @minor, @tiny = version_str.split(".").map{|e| e.to_i }
41
+ end
42
+
43
+ def <=>(other)
44
+ [:major, :minor, :tiny].each do | ver_part |
45
+ mine, theirs = send(ver_part), other.send(ver_part)
46
+ return mine <=> theirs unless mine == theirs
47
+ end
48
+ return 0
49
+ end
50
+ end
51
+
52
+ def self.extract_version_from_xml(io)
53
+ doc = REXML::Document.new(io)
54
+ version_text = doc.elements["rubygem/version"].text
55
+ end
56
+ end
data/test/sample.xml ADDED
@@ -0,0 +1,35 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <rubygem>
3
+ <dependencies>
4
+ <runtime type="array">
5
+ <dependency>
6
+ <name>progressbar</name>
7
+ <requirements>&gt;= 0</requirements>
8
+ </dependency>
9
+ </runtime>
10
+ <development type="array">
11
+ <dependency>
12
+ <name>hoe</name>
13
+ <requirements>&gt;= 2.9.1</requirements>
14
+ </dependency>
15
+ <dependency>
16
+ <name>flexmock</name>
17
+ <requirements>&gt;= 0</requirements>
18
+ </dependency>
19
+ </development>
20
+ </dependencies>
21
+ <name>tracksperanto</name>
22
+ <downloads type="integer">14827</downloads>
23
+ <info>Tracksperanto is a universal 2D-track translator between many apps.</info>
24
+ <version-downloads type="integer">15</version-downloads>
25
+ <version>2.4.1</version>
26
+ <homepage-uri>http://guerilla-di.org/tracksperanto</homepage-uri>
27
+ <bug-tracker-uri nil="true"></bug-tracker-uri>
28
+ <source-code-uri nil="true"></source-code-uri>
29
+ <gem-uri>http://rubygems.org/gems/tracksperanto-2.4.1.gem</gem-uri>
30
+ <project-uri>http://rubygems.org/gems/tracksperanto</project-uri>
31
+ <authors>Julik Tarkhanov</authors>
32
+ <mailing-list-uri nil="true"></mailing-list-uri>
33
+ <documentation-uri nil="true"></documentation-uri>
34
+ <wiki-uri nil="true"></wiki-uri>
35
+ </rubygem>
@@ -0,0 +1,29 @@
1
+ require "test/unit"
2
+ require "update_hints"
3
+ require 'rubygems'
4
+ require 'flexmock'
5
+ require 'flexmock/test_unit'
6
+
7
+ class TestUpdateHints < Test::Unit::TestCase
8
+ def test_nothing_raised_on_nonexisting_gem
9
+ assert_nothing_raised { UpdateHints.version_check(">>nonexisting<<", "123") }
10
+ end
11
+
12
+ def test_version_check_properly_output
13
+ xml = File.open(File.dirname(__FILE__) + "/sample.xml")
14
+ output = ''
15
+ flexmock(UpdateHints).should_receive(:open).with("http://rubygems.org/api/v1/gems/tracksperanto.xml").once.and_return(xml)
16
+
17
+ UpdateHints.version_check("tracksperanto", "1.2.3", output)
18
+ assert_equal "Your version of tracksperanto is probably out of date\n(the current version is 2.4.1, but you have 1.2.3).\nPlease consider updating (run `gem update tracksperanto`)", output
19
+ end
20
+
21
+ def test_version_check_stays_silent_on_success
22
+ xml = File.open(File.dirname(__FILE__) + "/sample.xml")
23
+ output = ''
24
+ flexmock(UpdateHints).should_receive(:open).with("http://rubygems.org/api/v1/gems/tracksperanto.xml").once.and_return(xml)
25
+ UpdateHints.version_check("tracksperanto", "2.4.1", output)
26
+ assert_equal "", output
27
+ end
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: update_hints
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Julik Tarkhanov
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-25 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: flexmock
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: hoe
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 41
44
+ segments:
45
+ - 2
46
+ - 9
47
+ - 1
48
+ version: 2.9.1
49
+ type: :development
50
+ version_requirements: *id002
51
+ description: Quickly checks rubygems.org for a new version o a given gem and advises the user on STDERR to install an update
52
+ email:
53
+ - me@julik.nl
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files:
59
+ - History.txt
60
+ - Manifest.txt
61
+ - README.txt
62
+ files:
63
+ - .autotest
64
+ - History.txt
65
+ - Manifest.txt
66
+ - README.txt
67
+ - Rakefile
68
+ - lib/update_hints.rb
69
+ - test/sample.xml
70
+ - test/test_update_hints.rb
71
+ - .gemtest
72
+ has_rdoc: true
73
+ homepage: http://github.com/julik/update_hints
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options:
78
+ - --main
79
+ - README.txt
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ requirements: []
101
+
102
+ rubyforge_project: update_hints
103
+ rubygems_version: 1.4.1
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Quickly checks rubygems.org for a new version o a given gem and advises the user on STDERR to install an update
107
+ test_files:
108
+ - test/test_update_hints.rb