version-check 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 82c9098875cd2f462c21ecdbbf7bd0271cd755a9
4
+ data.tar.gz: bb6c366865fb20255cf7892c71169d30c2a3c37c
5
+ SHA512:
6
+ metadata.gz: 707d9b5a42b7a28bbaede44a53fd511c7f05bfeabfdf0bbc1c7ef5c7f04641095fbbb86fedcee25664aed794c579b582dad4d72dc7754867cdec199c08302472
7
+ data.tar.gz: 205c185befb544077cd32f659a9a60a3c740d928b58fdf7406035a02cb43df15fa99f553ce6ef0eb13b3c26c09ba50e57b20c79a7254c8aff522ce767936d4fa
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ### 0.0.1 / 2020-02-24
2
+
3
+ * Everything is new. First release.
4
+
data/Manifest.txt ADDED
@@ -0,0 +1,8 @@
1
+ CHANGELOG.md
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ lib/version/check.rb
6
+ lib/version/check/version.rb
7
+ test/helper.rb
8
+ test/test_check.rb
data/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # version-check gem - up-to-date? - helpers for checking for / reporting outdated gem / library versions
2
+
3
+ * home :: [github.com/feedreader/pluto](https://github.com/feedreader/pluto)
4
+ * bugs :: [github.com/feedreader/pluto/issues](https://github.com/feedreader/pluto/issues)
5
+ * gem :: [rubygems.org/gems/version-check](https://rubygems.org/gems/version-check)
6
+ * rdoc :: [rubydoc.info/gems/version-check](http://rubydoc.info/gems/version-check)
7
+ * forum :: [groups.google.com/group/wwwmake](http://groups.google.com/group/wwwmake)
8
+
9
+
10
+ ## Usage
11
+
12
+ Up-to-date? Version check all your libraries / gems on start-up at runtime.
13
+
14
+ Let's say you have a script
15
+ that depends on many libraries / gems.
16
+ How can you make sure the minimum version requirements
17
+ are fulfilled?
18
+
19
+
20
+ Use the (global) `version_check` method in your script.
21
+ Example:
22
+
23
+ ``` ruby
24
+ outdated = version_check(
25
+ ['pakman', '1.1.0', Pakman::VERSION],
26
+ ['fetcher', '0.4.5', Fetcher::VERSION],
27
+ ['feedparser', '2.1.2', FeedParser::VERSION],
28
+ ['feedfilter', '1.1.1', FeedFilter::VERSION],
29
+ ['textutils', '1.4.0', TextUtils::VERSION],
30
+ ['logutils', '0.6.1', LogKernel::VERSION],
31
+ ['props', '1.2.0', Props::VERSION],
32
+
33
+ ['pluto-models', '1.5.4', Pluto::VERSION],
34
+ ['pluto-update', '1.6.3', PlutoUpdate::VERSION],
35
+ ['pluto-merge', '1.1.0', PlutoMerge::VERSION] )
36
+
37
+ pp outdated
38
+ ```
39
+
40
+ Pass along the version check records where the record items are 1) the name of the library / gem, 2) the minimum version requirement and 3) the "live" used version - for example,
41
+ `Pluto::VERSION` will become at runtime `1.5.3` or something - depending
42
+ on the installation / setup.
43
+
44
+ If all libraries / gems are up-to-date
45
+ this will result in an empty outdated list / array:
46
+
47
+ ``` ruby
48
+ []
49
+ ```
50
+
51
+ And if some libraries / gems are NOT matching the minimum version requirement
52
+ the version record will get returned in the outdated list / array
53
+ resulting in, for example:
54
+
55
+ ``` ruby
56
+ [['pluto-models', '1.5.4', '1.5.3'],
57
+ ['pluto-update', '1.6.3', '1.4.1']]
58
+ ```
59
+
60
+ Note: For now the version in use MUST always be greater or equal
61
+ to the minimum version requirement.
62
+
63
+ And the minimum requirement might be just a major (e.g. `2` same as `2.x.x`)
64
+ or a major plus minor (e.g. `2.1` same as `2.1.x`) version.
65
+
66
+
67
+
68
+ ### Bonus: Sorry - Cannot continue; please update the outdated gem(s)
69
+
70
+ Use the (global) `version_check!` method (with a bang `!`) in your script
71
+ to automatically 1) check all versions, 2) report all outdated libraries / gems, 3) ask for an update and 4) exit. Example:
72
+
73
+ ``` ruby
74
+ version_check!(
75
+ ['pakman', '1.1.0', Pakman::VERSION],
76
+ ['fetcher', '0.4.5', Fetcher::VERSION],
77
+ ['feedparser', '2.1.2', FeedParser::VERSION],
78
+ ['feedfilter', '1.1.1', FeedFilter::VERSION],
79
+ ['textutils', '1.4.0', TextUtils::VERSION],
80
+ ['logutils', '0.6.1', LogKernel::VERSION],
81
+ ['props', '1.2.0', Props::VERSION],
82
+
83
+ ['pluto-models', '1.5.4', Pluto::VERSION],
84
+ ['pluto-update', '1.6.3', PlutoUpdate::VERSION],
85
+ ['pluto-merge', '1.1.0', PlutoMerge::VERSION] )
86
+ ```
87
+
88
+ Case 1: If all libraries / gems are up-to-date nothing happens.
89
+
90
+ Case 2: If some libraries / gems are NOT matching the minimum version requirement
91
+ this will result in, for example:
92
+
93
+ ```
94
+ !!! ERROR: version check failed - 2 outdated gem(s):"
95
+ pluto-models - min version required 1.5.4 > used/installed version 1.5.3
96
+ pluto-update - min version required 1.6.3 > used/installed version 1.4.1
97
+
98
+ sorry - cannot continue; please update the outdated gem(s)
99
+ ```
100
+
101
+
102
+
103
+ ## License
104
+
105
+ The `version-check` scripts are dedicated to the public domain.
106
+ Use it as you please with no restrictions whatsoever.
107
+
108
+ ## Questions? Comments?
109
+
110
+ Send them along to the [wwwmake Forum/Mailing List](http://groups.google.com/group/wwwmake).
111
+ Thanks!
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ require 'hoe'
2
+ require './lib/version/check/version.rb'
3
+
4
+ Hoe.spec 'version-check' do
5
+
6
+ self.version = VersionCheck::VERSION
7
+
8
+ self.summary = "version-check - up-to-date? - helpers for checking for / reporting outdated gem / library versions"
9
+ self.description = summary
10
+
11
+ self.urls = ['https://github.com/feedreader/pluto']
12
+
13
+ self.author = 'Gerald Bauer'
14
+ self.email = 'wwwmake@googlegroups.com'
15
+
16
+
17
+ # switch extension to .markdown for gihub formatting
18
+ self.readme_file = 'README.md'
19
+ self.history_file = 'CHANGELOG.md'
20
+
21
+ self.extra_deps = []
22
+
23
+ self.licenses = ['Public Domain']
24
+
25
+ self.spec_extras = {
26
+ required_ruby_version: '>= 2.2.2'
27
+ }
28
+
29
+ end
@@ -0,0 +1,67 @@
1
+ require 'pp'
2
+
3
+ # our own code
4
+ require 'version/check/version' # note: let version always go first
5
+
6
+
7
+
8
+ #####
9
+ # simple version check
10
+ # used version MUST always be greater or equal than minimum requirement
11
+
12
+ def version_check( *versions )
13
+
14
+ outdated = [] ## list of outdated entries
15
+
16
+ versions.each do |rec|
17
+ name = rec[0]
18
+ ## convert "2.0.17" to [2,0,17] or
19
+ ## "2.1" to [2,1]
20
+ ## note: use Integer and NOT to_i; will through exception if version is not a number
21
+ min_version = rec[1].split( '.' ).map { |part| Integer(part) }
22
+ used_version = rec[2].split( '.' ).map { |part| Integer(part) }
23
+
24
+ ## check for minimum version requirement
25
+ min_version.zip( used_version ) do |part|
26
+ min_num = part[0]
27
+ used_num = part[1] || 0 ## support unlikley edge case (used_version has less version parts than min_version)
28
+ if used_num > min_num
29
+ ## used version is greater; stop comparing
30
+ break
31
+ elsif used_num == min_num
32
+ ## continue compare with next version number part
33
+ next
34
+ else
35
+ ## used version is smaller; add and report outdated (!!) entry; stop comparing
36
+ outdated << rec
37
+ break
38
+ end
39
+ end
40
+ end
41
+
42
+ outdated
43
+ end
44
+
45
+
46
+ def version_check!( *versions )
47
+ outdated = version_check( *versions )
48
+
49
+ if outdated.size > 0 ## any outdated gems/libraries
50
+ puts "!!! error: version check failed - #{outdated.size} outdated gem(s):"
51
+ outdated.each do |rec|
52
+ name = rec[0]
53
+ min_version = rec[1]
54
+ used_version = rec[2]
55
+ puts " #{name} - min version required #{min_version} > used/installed version #{used_version}"
56
+ end
57
+ puts
58
+ puts "sorry - cannot continue; please update the outdated gem(s)"
59
+
60
+ exit 1
61
+ end
62
+ end
63
+
64
+
65
+
66
+ # say hello
67
+ puts VersionCheck.banner if $DEBUG || (defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG)
@@ -0,0 +1,20 @@
1
+
2
+ module VersionCheck
3
+ MAJOR = 0 ## todo: namespace inside version or something - why? why not??
4
+ MINOR = 1
5
+ PATCH = 0
6
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
7
+
8
+ def self.version
9
+ VERSION
10
+ end
11
+
12
+ def self.banner
13
+ "version-check/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
14
+ end
15
+
16
+ def self.root
17
+ "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
18
+ end
19
+ end # module VersionCheck
20
+
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+
2
+ ## minitest setup
3
+ require 'minitest/autorun'
4
+
5
+
6
+ $RUBYLIBS_DEBUG = true
7
+
8
+ ## our own code
9
+ require 'version/check'
10
+
@@ -0,0 +1,55 @@
1
+ ###
2
+ # to run use
3
+ # ruby -I ./lib -I ./test test/test_check.rb
4
+
5
+
6
+ require 'helper'
7
+
8
+
9
+ class TestCheck < MiniTest::Test
10
+
11
+
12
+ def test_update_to_date
13
+
14
+ versions_a =
15
+ [['pakman', '1.1.0', '1.1.1'],
16
+ ['fetcher', '0.4.5', '0.5.4'],
17
+ ['feedparser', '2.1.2', '2.2.1'],
18
+ ['feedfilter', '1.1', '1.1.14'],
19
+ ['textutils', '2', '2.0.5'],
20
+ ['logutils', '0.6', '0.6.0'],
21
+ ['props', '1.2.1', '1.3.0'],
22
+
23
+ ['pluto-models', '1.5.4', '1.5.7'],
24
+ ['pluto-update', '1.6', '2.0.0'],
25
+ ['pluto-merge', '1.1.0', '1.2.0']]
26
+
27
+ versions_a_outdated = []
28
+
29
+ assert_equal versions_a_outdated, version_check( *versions_a )
30
+ end
31
+
32
+ def test_outdated
33
+ versions_b =
34
+ [['pakman', '1.1.0', '1.0.1'],
35
+ ['fetcher', '0.4.5', '0.5.4'],
36
+ ['feedparser', '2.1.2', '2.2.1'],
37
+ ['feedfilter', '1.1', '1.1.1'],
38
+ ['textutils', '2', '1.2.7'],
39
+ ['logutils', '0.6', '0.6.0'],
40
+ ['props', '1.2.1', '1.3.0'],
41
+
42
+ ['pluto-models', '1.5.4', '1.5.7'],
43
+ ['pluto-update', '1.6', '1.5.11'],
44
+ ['pluto-merge', '1.1.0', '1.2.0']]
45
+
46
+ versions_b_outdated =
47
+ [['pakman', '1.1.0', '1.0.1'],
48
+ ['textutils', '2', '1.2.7'],
49
+ ['pluto-update', '1.6', '1.5.11']]
50
+
51
+
52
+ assert_equal versions_b_outdated, version_check( *versions_b )
53
+ end
54
+
55
+ end # class TestCheck
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: version-check
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gerald Bauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hoe
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.16'
41
+ description: version-check - up-to-date? - helpers for checking for / reporting outdated
42
+ gem / library versions
43
+ email: wwwmake@googlegroups.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - CHANGELOG.md
48
+ - Manifest.txt
49
+ - README.md
50
+ files:
51
+ - CHANGELOG.md
52
+ - Manifest.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/version/check.rb
56
+ - lib/version/check/version.rb
57
+ - test/helper.rb
58
+ - test/test_check.rb
59
+ homepage: https://github.com/feedreader/pluto
60
+ licenses:
61
+ - Public Domain
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options:
65
+ - "--main"
66
+ - README.md
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 2.2.2
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.5.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: version-check - up-to-date? - helpers for checking for / reporting outdated
85
+ gem / library versions
86
+ test_files: []