Sha256: 0a5a7d766d60b49b3669bf7a01b04d92a66ae133b2c6fea26044bbfaeb91fa18

Contents?: true

Size: 1.25 KB

Versions: 9

Compression:

Stored size: 1.25 KB

Contents

# encoding: utf-8

require "desi/http_client"
require "json"

module Desi
  class Upstream

    class Release < Struct.new(:version_name, :download_url)
      def to_s
        name
      end

      def name
        "elasticsearch-#{version}"
      end

      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.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_tags.
        map {|v| Release.new(v['name'], v['tarball_url']) }.
        sort
    end

    def latest_release
      releases.first
    end

    def find_release(name_or_version)
      releases.detect {|r| r === name_or_version }
    end

    private

    def fetch_tags
      JSON.parse @client.get('/repos/elasticsearch/elasticsearch/tags').body
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
desi-0.6.4 lib/desi/upstream.rb
desi-0.6.2 lib/desi/upstream.rb
desi-0.6.1 lib/desi/upstream.rb
desi-0.6.0 lib/desi/upstream.rb
desi-0.5.0 lib/desi/upstream.rb
desi-0.4.0 lib/desi/upstream.rb
desi-0.3.0 lib/desi/upstream.rb
desi-0.2.9 lib/desi/upstream.rb
desi-0.2.8 lib/desi/upstream.rb