lib/desi/upstream.rb in desi-0.2.7 vs lib/desi/upstream.rb in desi-0.2.8
- old
+ new
@@ -4,40 +4,49 @@
require "json"
module Desi
class Upstream
- class Release < Struct.new(:archive_name, :description, :release_date, :download_url)
+ class Release < Struct.new(:version_name, :download_url)
def to_s
- archive_name
+ name
end
def name
- @name ||= archive_name.scan(/^(elasticsearch-.*?)\.tar\.gz$/).flatten.first
+ "elasticsearch-#{version}"
end
- def version
- @version ||= archive_name.scan(/^elasticsearch-(.*?)\.tar\.gz$/).flatten.first
+ def filename
+ "elasticsearch-#{version}.tar.gz"
end
def ===(name_or_version)
name_or_version == version || name_or_version == name || name_or_version == "v#{version}"
end
def <=>(other)
- other.release_date <=> other.release_date
+ other.sortable_version <=> sortable_version
end
+
+ def version
+ version_name.gsub(/^v/, '')
+ end
+
+ protected
+
+ def sortable_version
+ version_name.split('.').map {|c| c.to_i }
+ end
end
def initialize(opts = {})
@client = opts.fetch(:http_client_factory, Desi::HttpClient).new('https://api.github.com/')
end
def releases
- @releases ||= fetch_releases.
- select {|v| v['content_type'] == 'application/gzip' }.
- map {|v| Release.new(v['name'], v['description'], v['created_at'], v['html_url']) }.
+ @releases ||= fetch_tags.
+ map {|v| Release.new(v['name'], v['tarball_url']) }.
sort
end
def latest_release
releases.first
@@ -47,11 +56,11 @@
releases.detect {|r| r === name_or_version }
end
private
- def fetch_releases
- JSON.parse @client.get('/repos/elasticsearch/elasticsearch/downloads').body
+ def fetch_tags
+ JSON.parse @client.get('/repos/elasticsearch/elasticsearch/tags').body
end
end
end