latest_ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDA2MGExOTViMTA2YTU0MGEyMzBjYTRmZDRkYjVhZTZjZmQ5MDNkOA==
5
+ data.tar.gz: !binary |-
6
+ ZGFkMDM1N2U5MGFjNDRjZWNmMDlkYzliZGYzMzQ0MjJlYzcyNzJmOA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YmQzMTE0YzBjZTA4M2I5YTIxNWQ0YjE1YmE2NjM5NWNmZTNiZDBmZWMzYmYy
10
+ YmE4OWI2Njk1MDVjNjU2MDM2YTMzZmYyNzUyNmUxZDM4NTc5ZjA0MDU2NmJh
11
+ NTYwYjViNWQxMTU0MmRmMmZkNjg3MDVmOTBlOTRiMDBjN2VhYWQ=
12
+ data.tar.gz: !binary |-
13
+ MWQ4ZGJlYjkxN2E3NDZiMWRkMDUyNTQ1MjJiM2I0MjVmMzliOWZmMDI2MWNl
14
+ OTc3YTViZmI0NGVhODQ3NzE0ZTE0YzJjNDJjMWUyNGE5ZDdhYjUwZDZhMjg0
15
+ NTJkOGM3NTVhZGEzMTJlMjBiNjdlNmE5OTU4YTRhMzE2NmI4M2I=
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *~
2
+ *.gem
3
+ Gemfile.lock
4
+ .rbx
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ Latest Ruby changelog
2
+ =====================
3
+
4
+ ### v0.0.1 (April 16, 2013)
5
+
6
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
data/LICENCE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2013 Kyrylo Silin
2
+
3
+ This software is provided 'as-is', without any express or implied
4
+ warranty. In no event will the authors be held liable for any damages
5
+ arising from the use of this software.
6
+
7
+ Permission is granted to anyone to use this software for any purpose,
8
+ including commercial applications, and to alter it and redistribute it
9
+ freely, subject to the following restrictions:
10
+
11
+ 1. The origin of this software must not be misrepresented; you must not
12
+ claim that you wrote the original software. If you use this software
13
+ in a product, an acknowledgment in the product documentation would be
14
+ appreciated but is not required.
15
+
16
+ 2. Altered source versions must be plainly marked as such, and must not be
17
+ misrepresented as being the original software.
18
+
19
+ 3. This notice may not be removed or altered from any source distribution.
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ Latest Ruby
2
+ ===========
3
+
4
+ * Repository: [https://github.com/kyrylo/latest_ruby][repo]
5
+
6
+ Description
7
+ -----------
8
+
9
+ The purpose of this library is to answer a simple but capacious question: “What
10
+ is the latest version of Ruby now?”. It can also be asked for the latest
11
+ versions of Rubinius, JRuby, MagLev, MacRuby.
12
+
13
+ Installation
14
+ ------------
15
+
16
+ gem install latest_ruby
17
+
18
+ Synopsis
19
+ --------
20
+
21
+ I find this library useful for the [`pry-doc` Pry plugin][prydoc]. Namely, for
22
+ automation of generation the latest documentation for Rubies.
23
+
24
+ ### Usage
25
+
26
+ Let's find out the latest versions of Rubies.
27
+
28
+ ```ruby
29
+ # MRI 2.0
30
+ Latest.ruby.version.to_s #=> "2.0.0-p0"
31
+ # The same.
32
+ Latest.ruby20.version.to_s
33
+
34
+ # MRI 1.9
35
+ Latest.ruby19.version.to_s #=> "1.9.3-p392"
36
+
37
+ # MRI 1.8
38
+ Latest.ruby18.version.to_s #=> "1.8.7-p371"
39
+
40
+ # JRuby.
41
+ Latest.jruby.version.to_s #=> "1.7.3"
42
+
43
+ # Rubinius.
44
+ Latest.rubinius.version.to_s #=> "1.2.4"
45
+ # The same.
46
+ Latest.rbx.version.to_s
47
+
48
+ # MagLev
49
+ Latest.maglev.version.to_s #=> "1.0.0"
50
+
51
+ # MacRuby
52
+ Latest.macruby.version.to_s #=> "0.12"
53
+ ```
54
+
55
+ Latest Ruby also provides one useful (well, it's useful for me, at least) way to
56
+ retrieve a download link for a Ruby.
57
+
58
+ ```ruby
59
+ Latest.ruby.link #=> "http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz"
60
+ # The same.
61
+ Latest.ruby.link('.tar.gz') #=> "http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz"
62
+
63
+ Latest.ruby.link('.tar.bz2') #=> "http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.bz2"
64
+ Latest.ruby.link('.zip') #=> "http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.zip"
65
+ ```
66
+
67
+ Limitations
68
+ -----------
69
+
70
+ ### OS support
71
+
72
+ Latest Ruby is a cross-platform library.
73
+
74
+ ### Rubies
75
+
76
+ * Ruby 1.9.3 and higher
77
+
78
+ Please, ping me, if you need support for other Ruby implementations. Or, if you
79
+ prefer, send a pull request. Currently, the library is unbelievably simple.
80
+ Ideas and suggestions are welcome (just file issues).
81
+
82
+ Licence
83
+ -------
84
+
85
+ The project uses Zlib licence. See LICENCE file for more information.
86
+
87
+ [repo]: https://github.com/kyrylo/latest_ruby
88
+ [prydoc]: https://github.com/pry/pry-doc
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ def quiet
2
+ ENV['VERBOSE'] ? '' : '-q'
3
+ end
4
+
5
+ def test_files
6
+ paths = FileList['spec/**/*_spec.rb']
7
+ paths.shuffle!.join(' ')
8
+ end
9
+
10
+ desc "Run tests"
11
+ task :test do
12
+ exec "bacon -Ispec #{ quiet } #{ test_files }"
13
+ end
14
+
15
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'latest_ruby'
3
+ s.version = File.read('VERSION')
4
+ s.date = Time.now.strftime('%Y-%m-%d')
5
+ s.summary = 'Answers the question of what the latest Ruby version is'
6
+ s.description = 'Knows about MRI, Rubinius, JRuby, MagLev and MacRuby.'
7
+ s.author = 'Kyrylo Silin'
8
+ s.email = 'kyrylosilin@gmail.com'
9
+ s.homepage = 'https://github.com/kyrylo/latest_ruby'
10
+ s.licenses = 'zlib'
11
+
12
+ s.require_path = 'lib'
13
+ s.files = `git ls-files`.split("\n")
14
+
15
+ s.add_runtime_dependency 'versionomy'
16
+
17
+ s.add_development_dependency 'bacon'
18
+ s.add_development_dependency 'rake'
19
+ s.add_development_dependency 'pry'
20
+ end
@@ -0,0 +1,56 @@
1
+ require_relative 'latest_ruby/ruby'
2
+ require_relative 'latest_ruby/ruby_version'
3
+ require_relative 'latest_ruby/rubies/mri'
4
+ require_relative 'latest_ruby/rubies/jruby'
5
+ require_relative 'latest_ruby/rubies/rubinius'
6
+ require_relative 'latest_ruby/rubies/maglev'
7
+ require_relative 'latest_ruby/rubies/macruby'
8
+ require_relative 'latest_ruby/retrievers/mri_retriever'
9
+ require_relative 'latest_ruby/retrievers/jruby_retriever'
10
+ require_relative 'latest_ruby/retrievers/rubinius_retriever'
11
+ require_relative 'latest_ruby/retrievers/maglev_retriever'
12
+ require_relative 'latest_ruby/retrievers/macruby_retriever'
13
+
14
+ module Latest
15
+
16
+ # The VERSION file must be in the root directory of the library.
17
+ VERSION_FILE = File.expand_path('../../VERSION', __FILE__)
18
+
19
+ VERSION = File.exist?(VERSION_FILE) ?
20
+ File.read(VERSION_FILE).chomp : '(could not find VERSION file)'
21
+
22
+ class << self
23
+ def ruby20
24
+ Ruby.new(MRI.new('2.0', MRIRetriever.new))
25
+ end
26
+
27
+ # The latest Ruby version by default.
28
+ alias_method :ruby, :ruby20
29
+
30
+ def ruby19
31
+ Ruby.new(MRI.new('1.9', MRIRetriever.new))
32
+ end
33
+
34
+ def ruby18
35
+ Ruby.new(MRI.new('1.8', MRIRetriever.new))
36
+ end
37
+
38
+ def jruby
39
+ Ruby.new(JRuby.new(JRubyRetriever.new))
40
+ end
41
+
42
+ def rubinius
43
+ Ruby.new(Rubinius.new(RubiniusRetriever.new))
44
+ end
45
+ alias_method :rbx, :rubinius
46
+
47
+ def maglev
48
+ Ruby.new(MagLev.new(MagLevRetriever.new))
49
+ end
50
+
51
+ def macruby
52
+ Ruby.new(MacRuby.new(MacRubyRetriever.new))
53
+ end
54
+ end
55
+
56
+ end
@@ -0,0 +1,13 @@
1
+ require 'net/http'
2
+
3
+ module Latest
4
+ class JRubyRetriever
5
+
6
+ def retrieve(jruby)
7
+ page = Net::HTTP.get(URI(jruby.source))
8
+ ver = page.scan(/Current Release: JRuby (.+)<\/h2>/).flatten.first
9
+ RubyVersion.new(ver)
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Latest
2
+ class MacRubyRetriever
3
+
4
+ def retrieve(macruby)
5
+ page = Net::HTTP.get(URI(macruby.source))
6
+ page.scan(/MacRuby (.+)\.zip/).
7
+ uniq.flatten.map { |v| RubyVersion.new(v) }.max
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Latest
2
+ class MagLevRetriever
3
+
4
+ def retrieve(maglev)
5
+ page = Net::HTTP.get(URI(maglev.source))
6
+ page.scan(/MagLev-(\d\.\d\.\d)\.tar\.gz/).
7
+ uniq.flatten.map { |v| RubyVersion.new(v) }.max
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'net/http'
2
+
3
+ module Latest
4
+ class MRIRetriever
5
+
6
+ def retrieve(mri)
7
+ page = Net::HTTP.get(URI(mri.source + mri.short_ver + '/'))
8
+ page.scan(/(#{ Regexp.escape(mri.short_ver) }\.\d-[a-z0-9]+)\.zip/x).
9
+ uniq.flatten.map { |v| RubyVersion.new(v) }.max
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ require 'net/http'
2
+ require 'rexml/document'
3
+
4
+ module Latest
5
+ class RubiniusRetriever
6
+
7
+ include REXML
8
+
9
+ def retrieve(rbx)
10
+ page = Net::HTTP.get(URI(rbx.source))
11
+ xml = Document.new(page)
12
+ all_versions = XPath.match(xml, '//Contents//Key').map(&:text)
13
+ candidates = all_versions.find_all { |v| v =~ /\Arubinius-/ }
14
+ stables = candidates.flat_map { |v| v.scan(/-(\d\.\d\.\d)\.tar/) }.flatten
15
+ stables.map { |v| RubyVersion.new(v) }.max
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ module Latest
2
+ class JRuby
3
+
4
+ SOURCE = 'http://jruby.org.s3.amazonaws.com/downloads/'
5
+ WEB_SOURCE = 'http://jruby.org/download'
6
+ AVAILABLE_EXTS = ['.tar.gz', '.zip']
7
+
8
+ attr_reader :source, :web_source
9
+
10
+ def initialize(retriever)
11
+ @retriever = retriever
12
+ @source = WEB_SOURCE
13
+ end
14
+
15
+ def version
16
+ @version ||= @retriever.retrieve(self)
17
+ end
18
+
19
+ def link(ext = '.tar.gz')
20
+ if AVAILABLE_EXTS.include?(ext)
21
+ SOURCE + '/' + version.to_s + '/jruby-bin-' + version.to_s + ext
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ module Latest
2
+ class MacRuby
3
+
4
+ SOURCE = 'http://macruby.jp/files/'
5
+ AVAILABLE_EXTS = ['.zip']
6
+
7
+ attr_reader :source
8
+
9
+ def initialize(retriever)
10
+ @retriever = retriever
11
+ @source = SOURCE
12
+ end
13
+
14
+ def version
15
+ @version ||= @retriever.retrieve(self)
16
+ end
17
+
18
+ def link(ext = '.zip')
19
+ if AVAILABLE_EXTS.include?(ext)
20
+ source + 'MacRuby ' + version.to_s + ext
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module Latest
2
+ class MagLev
3
+
4
+ SOURCE = 'http://glass-downloads.gemstone.com/maglev/'
5
+ AVAILABLE_EXTS = ['.tar.gz']
6
+
7
+ attr_reader :source
8
+
9
+ def initialize(retriever)
10
+ @retriever = retriever
11
+ @source = SOURCE
12
+ end
13
+
14
+ def version
15
+ @version ||= @retriever.retrieve(self)
16
+ end
17
+
18
+ def link(ext = '.tar.gz')
19
+ if AVAILABLE_EXTS.include?(ext)
20
+ source + 'MagLev-' + version.to_s + ext
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ module Latest
2
+ class MRI
3
+
4
+ SOURCE = 'http://ftp.ruby-lang.org/pub/ruby/'
5
+ AVAILABLE_EXTS = ['.tar.gz', '.zip', '.tar.bz2']
6
+
7
+ attr_reader :short_ver, :source
8
+
9
+ def initialize(short_ver, retriever)
10
+ @short_ver = short_ver
11
+ @retriever = retriever
12
+ @source = SOURCE
13
+ end
14
+
15
+ def version
16
+ @version ||= @retriever.retrieve(self)
17
+ end
18
+
19
+ def link(ext = '.tar.gz')
20
+ if AVAILABLE_EXTS.include?(ext)
21
+ source + short_ver + '/ruby-' + version.to_s + ext
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ module Latest
2
+ class Rubinius
3
+
4
+ SOURCE = 'http://asset.rubini.us/'
5
+ AVAILABLE_EXTS = ['.tar.gz']
6
+
7
+ attr_reader :source
8
+
9
+ def initialize(retriever)
10
+ @retriever = retriever
11
+ @source = SOURCE
12
+ end
13
+
14
+ def version
15
+ @version ||= @retriever.retrieve(self)
16
+ end
17
+
18
+ def link(ext = '.tar.gz')
19
+ if AVAILABLE_EXTS.include?(ext)
20
+ source + 'rubinius-' + version.to_s + ext
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ require 'forwardable'
2
+
3
+ module Latest
4
+ class Ruby
5
+
6
+ extend Forwardable
7
+
8
+ def initialize(ruby)
9
+ @ruby = ruby
10
+ end
11
+
12
+ def_delegators :@ruby, :link, :version
13
+
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ require 'forwardable'
2
+ require 'versionomy'
3
+
4
+ module Latest
5
+ class RubyVersion
6
+
7
+ extend Forwardable
8
+
9
+ def initialize(version)
10
+ @version = get_version(version)
11
+ end
12
+
13
+ def <=>(other)
14
+ @version <=> other.instance_variable_get(:@version)
15
+ end
16
+
17
+ def_delegators :@version, :to_s
18
+
19
+ private
20
+
21
+ def get_version(ver)
22
+ Versionomy.parse(ver)
23
+ end
24
+
25
+ end
26
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'bacon'
2
+ require 'pry'
3
+
4
+ require_relative '../lib/latest_ruby'
5
+
6
+ puts "Ruby: #{ RUBY_VERSION }; Latest Ruby version: #{ Latest::VERSION }"
@@ -0,0 +1,7 @@
1
+ require_relative 'helper'
2
+
3
+ describe Latest do
4
+ it "works" do
5
+ true.should == true
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: latest_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kyrylo Silin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: versionomy
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bacon
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Knows about MRI, Rubinius, JRuby, MagLev and MacRuby.
70
+ email: kyrylosilin@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - .gitignore
76
+ - CHANGELOG.md
77
+ - Gemfile
78
+ - LICENCE
79
+ - README.md
80
+ - Rakefile
81
+ - VERSION
82
+ - latest_ruby.gemspec
83
+ - lib/latest_ruby.rb
84
+ - lib/latest_ruby/retrievers/jruby_retriever.rb
85
+ - lib/latest_ruby/retrievers/macruby_retriever.rb
86
+ - lib/latest_ruby/retrievers/maglev_retriever.rb
87
+ - lib/latest_ruby/retrievers/mri_retriever.rb
88
+ - lib/latest_ruby/retrievers/rubinius_retriever.rb
89
+ - lib/latest_ruby/rubies/jruby.rb
90
+ - lib/latest_ruby/rubies/macruby.rb
91
+ - lib/latest_ruby/rubies/maglev.rb
92
+ - lib/latest_ruby/rubies/mri.rb
93
+ - lib/latest_ruby/rubies/rubinius.rb
94
+ - lib/latest_ruby/ruby.rb
95
+ - lib/latest_ruby/ruby_version.rb
96
+ - spec/helper.rb
97
+ - spec/latest_ruby_spec.rb
98
+ homepage: https://github.com/kyrylo/latest_ruby
99
+ licenses:
100
+ - zlib
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.0.3
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Answers the question of what the latest Ruby version is
122
+ test_files: []
123
+ has_rdoc: