lib/desi/upstream.rb in desi-0.2.1 vs lib/desi/upstream.rb in desi-0.2.2
- old
+ new
@@ -4,14 +4,26 @@
require "json"
module Desi
class Upstream
- class Release < Struct.new(:name, :description, :release_date, :download_url)
+ class Release < Struct.new(:archive_name, :description, :release_date, :download_url)
def to_s
- self.name
+ archive_name
end
+
+ def name
+ @name ||= archive_name.scan(/^(elasticsearch-.*?)\.tar\.gz$/).flatten.first
+ end
+
+ def version
+ @version ||= archive_name.scan(/^elasticsearch-(.*?)\.tar\.gz$/).flatten.first
+ end
+
+ def ===(name_or_version)
+ name_or_version == version || name_or_version == name || name_or_version == "v#{version}"
+ end
end
def initialize(opts = {})
@client = opts.fetch(:http_client_factory, Desi::HttpClient).new('https://api.github.com/')
end
@@ -25,11 +37,11 @@
def latest_release
releases.first
end
- def find_release(name)
- releases.detect {|r| r.name == name || r.version == name }
+ def find_release(name_or_version)
+ releases.detect {|r| r === name_or_version }
end
private
def fetch_releases