latest_version 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7c9eda91f5e31c3f8ffaf4b8409ad51d5e263f5e16bee470e35cc3a5a4cd7e2
4
- data.tar.gz: 1fe6296ab059571050d045c6b4ee325b4e93a673f6f890a2740e3b4c9c0e8f8f
3
+ metadata.gz: dda6fe0f325a80126ace0f9e2b262e125caac6757562cc70a466b019aec8e587
4
+ data.tar.gz: f56342dfa1ea4ae6cfae2f70ee8602e4779858aae69da26656a74964425a8737
5
5
  SHA512:
6
- metadata.gz: a3e09434698acef61fff032e01f58043f9b59084884eea3470f38b464e0afaf81fac23454beff017de9c5c808cdcaa87a83641091422254ae7415b62d2097e23
7
- data.tar.gz: 3e6f1157dd745dba50d1d27ab2a20833cbf8925ac32ceab6fe273d1d5b6c2e05fbc3ca664122209398f3f4598079425887285f2cc604faa036da3e2da6169d8d
6
+ metadata.gz: bc5ad872e920e2397f326c61c116fd67bbf46023d349f93ab5bc6e54c979455a1ee4e33026ef9da166d06f9a05cf15b3042ac695673683307ff84adc283ad7a2
7
+ data.tar.gz: a62c72144017fcaa275d2242945b3add658c38989dc48df7731588741a5050efbd7cab3b40118d977e650197c8bcf39433c2b1e1d02012c43c27312695c66f0c
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.1] - 2020-02-15
11
+
12
+ ### Added
13
+
14
+ - Support for elixir and rust.
15
+ - Where possible, use Github API instead of page scraping.
16
+
17
+ ## [0.1.0] - 2019-02-15
18
+
19
+ ### Added
20
+
21
+ - Support for ruby, rails and python.
22
+
23
+ [unreleased]: https://github.com/zubin/latest_version/compare/v0.1.1...HEAD
24
+ [0.1.1]: https://github.com/zubin/latest_version/compare/v0.1.0...v0.1.1
25
+ [0.1.0]: https://github.com/zubin/latest_version/releases/tag/v0.1.0
data/README.md CHANGED
@@ -15,10 +15,12 @@ $ gem install latest_version
15
15
  ```sh
16
16
  $ latest_version --help
17
17
  Commands:
18
+ latest_version elixir # Returns latest version of elixir
18
19
  latest_version help [COMMAND] # Describe available commands or one specific command
19
20
  latest_version python # Returns latest version of python
20
21
  latest_version rails # Returns latest version of rails
21
22
  latest_version ruby # Returns latest version of ruby
23
+ latest_version rust # Returns latest version of rust
22
24
  ```
23
25
 
24
26
  ## Contributing
@@ -1,22 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
3
4
  require 'net/http'
4
5
  require 'uri'
5
6
 
6
7
  module LatestVersion
7
8
  LIBRARIES = {
9
+ elixir: -> { latest_github_release(repo: 'elixir-lang/elixir') },
8
10
  python: lambda {
9
- find(
11
+ find_text(
10
12
  url: 'https://www.python.org/',
11
13
  regex: %r{<p>Latest: <a href="/downloads/release/python-\d+/">Python (\d+\.\d+\.\d+)</a></p>},
12
14
  )
13
15
  },
14
- rails: lambda {
15
- find(url: 'https://rubyonrails.org/', regex: /Latest version &mdash; Rails ([\d\.]+)/)
16
- },
17
- ruby: lambda {
18
- find(url: 'https://www.ruby-lang.org/en/downloads/', regex: /current stable version is (\d+\.\d+\.\d+)\./)
19
- },
16
+ rails: -> { latest_github_release(repo: 'rails/rails') },
17
+ ruby: -> { latest_github_tag(repo: 'ruby/ruby').gsub('_', '.') },
18
+ rust: -> { latest_github_tag(repo: 'rust-lang/rust') },
20
19
  }.freeze
21
20
  UnknownLibraryError = Class.new(StandardError)
22
21
  private_constant :LIBRARIES
@@ -29,7 +28,18 @@ module LatestVersion
29
28
  LIBRARIES.keys.sort
30
29
  end
31
30
 
32
- private_class_method def self.find(url:, regex:)
31
+ private_class_method def self.find_text(url:, regex:)
33
32
  Net::HTTP.get(URI.parse(url))[regex, 1]
34
33
  end
34
+
35
+ private_class_method def self.latest_github_release(repo:)
36
+ json = Net::HTTP.get(URI("https://api.github.com/repos/#{repo}/releases/latest"))
37
+ JSON.parse(json, symbolize_names: true).fetch(:tag_name).gsub(/^v/, '')
38
+ end
39
+
40
+ private_class_method def self.latest_github_tag(repo:)
41
+ json = Net::HTTP.get(URI("https://api.github.com/repos/#{repo}/tags"))
42
+ tags = JSON.parse(json, symbolize_names: true)
43
+ tags.map { |tag| tag.fetch(:name).gsub(/^v/, '') }.reject { |name| name[/[a-z]/i] }.max
44
+ end
35
45
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LatestVersion
4
- VERSION = "0.1.0"
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: latest_version
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zubin Henner
@@ -120,6 +120,7 @@ files:
120
120
  - ".rspec"
121
121
  - ".rubocop.yml"
122
122
  - ".travis.yml"
123
+ - CHANGELOG.md
123
124
  - Gemfile
124
125
  - LICENSE
125
126
  - README.md