desi 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .rvmrc
19
+ .rbenv*
@@ -10,14 +10,14 @@ module Desi
10
10
 
11
11
  def initialize(opts = {})
12
12
  @destination_dir = Pathname(opts.fetch(:destination_dir, Desi::LocalInstall.new))
13
- @host = URI(opts.fetch(:host, 'http://cloud.github.com/'))
13
+ @host = URI(opts.fetch(:host, 'https://nodeload.github.com/'))
14
14
  @client = opts.fetch(:http_client_factory, Desi::HttpClient).new(@host)
15
15
  @verbose = opts[:verbose]
16
16
  end
17
17
 
18
18
  def download!(version, opts = {})
19
- path = "/downloads/elasticsearch/elasticsearch/#{version.archive_name}"
20
- destination_name = @destination_dir.join File.basename(version.archive_name)
19
+ path = "/elasticsearch/elasticsearch/tar.gz/#{version.version_name}"
20
+ destination_name = @destination_dir.join File.basename(version.filename)
21
21
 
22
22
  raise "ERROR: File #{destination_name} already present!" if destination_name.exist?
23
23
 
@@ -32,7 +32,7 @@ module Desi
32
32
  when Net::HTTPSuccess
33
33
  response
34
34
  when Net::HTTPRedirection
35
- fetch(response['location'], limit - 1)
35
+ get(response['location'], limit - 1)
36
36
  else
37
37
  raise response.error!
38
38
  end
@@ -8,6 +8,27 @@ module Desi
8
8
  # Elastic Search cluster
9
9
  class IndexManager
10
10
 
11
+ class Index
12
+ attr_reader :name, :number_of_documents
13
+
14
+ def initialize(name, data)
15
+ @name = name
16
+ @number_of_documents = data["docs"]["num_docs"] if data && data["docs"]
17
+ end
18
+
19
+ def to_s
20
+ @name
21
+ end
22
+
23
+ def inspect
24
+ "#{@name} (#{@number_of_documents} documents)"
25
+ end
26
+
27
+ def <=>(other)
28
+ @name <=> other.name
29
+ end
30
+ end
31
+
11
32
  # Initializes a Desi::IndexManager instance
12
33
  #
13
34
  # @param [#to_hash] opts Hash of extra opts
@@ -53,7 +74,7 @@ module Desi
53
74
  @outputter.puts "Indices from host #{@host} matching the pattern #{pattern.inspect}\n\n" if @verbose
54
75
 
55
76
  list = indices(pattern).sort
56
- list.each {|i| @outputter.puts i } if @verbose
77
+ list.each {|i| @outputter.puts i.inspect } if @verbose
57
78
  list
58
79
  end
59
80
 
@@ -78,7 +99,7 @@ module Desi
78
99
 
79
100
  indices(Regexp.new(pattern)).each do |index|
80
101
  @client.delete("/#{index}")
81
- @outputter.puts " * #{index}" if @verbose
102
+ @outputter.puts " * #{index.inspect}" if @verbose
82
103
  end
83
104
  end
84
105
 
@@ -110,9 +131,9 @@ module Desi
110
131
  private
111
132
 
112
133
  def indices(pattern)
113
- JSON.parse(@client.get('/_status').body)["indices"].keys.select {|i|
114
- i =~ pattern
115
- }
134
+ JSON.parse(@client.get('/_status').body)["indices"].map {|k, v|
135
+ Index.new(k, v) if k =~ pattern
136
+ }.compact
116
137
  end
117
138
 
118
139
  def to_uri(host_string)
data/lib/desi/runner.rb CHANGED
@@ -31,7 +31,7 @@ module Desi
31
31
  releases
32
32
  else
33
33
  puts "Here are #{limit == 0 ? 'all the' : "the #{limit} latest"} releases"
34
- releases.each {|rel| puts " - #{rel.name} (#{rel.release_date})" }
34
+ releases.each {|rel| puts " - #{rel.name}" }
35
35
  end
36
36
  end
37
37
 
data/lib/desi/upstream.rb CHANGED
@@ -6,17 +6,17 @@ require "json"
6
6
  module Desi
7
7
  class Upstream
8
8
 
9
- class Release < Struct.new(:archive_name, :description, :release_date, :download_url)
9
+ class Release < Struct.new(:version_name, :download_url)
10
10
  def to_s
11
- archive_name
11
+ name
12
12
  end
13
13
 
14
14
  def name
15
- @name ||= archive_name.scan(/^(elasticsearch-.*?)\.tar\.gz$/).flatten.first
15
+ "elasticsearch-#{version}"
16
16
  end
17
17
 
18
- def version
19
- @version ||= archive_name.scan(/^elasticsearch-(.*?)\.tar\.gz$/).flatten.first
18
+ def filename
19
+ "elasticsearch-#{version}.tar.gz"
20
20
  end
21
21
 
22
22
  def ===(name_or_version)
@@ -24,7 +24,17 @@ module Desi
24
24
  end
25
25
 
26
26
  def <=>(other)
27
- other.release_date <=> other.release_date
27
+ other.sortable_version <=> sortable_version
28
+ end
29
+
30
+ def version
31
+ version_name.gsub(/^v/, '')
32
+ end
33
+
34
+ protected
35
+
36
+ def sortable_version
37
+ version_name.split('.').map {|c| c.to_i }
28
38
  end
29
39
  end
30
40
 
@@ -33,9 +43,8 @@ module Desi
33
43
  end
34
44
 
35
45
  def releases
36
- @releases ||= fetch_releases.
37
- select {|v| v['content_type'] == 'application/gzip' }.
38
- map {|v| Release.new(v['name'], v['description'], v['created_at'], v['html_url']) }.
46
+ @releases ||= fetch_tags.
47
+ map {|v| Release.new(v['name'], v['tarball_url']) }.
39
48
  sort
40
49
  end
41
50
 
@@ -49,8 +58,8 @@ module Desi
49
58
 
50
59
  private
51
60
 
52
- def fetch_releases
53
- JSON.parse @client.get('/repos/elasticsearch/elasticsearch/downloads').body
61
+ def fetch_tags
62
+ JSON.parse @client.get('/repos/elasticsearch/elasticsearch/tags').body
54
63
  end
55
64
 
56
65
  end
data/lib/desi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Desi
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.8"
3
3
  end
@@ -28,13 +28,13 @@ describe Desi::IndexManager do
28
28
  describe "#list" do
29
29
  context "with no specified pattern" do
30
30
  it "returns the names of all indices" do
31
- subject.list.should == %w[bar foo]
31
+ subject.list.map(&:name).should == %w[bar foo]
32
32
  end
33
33
  end
34
34
 
35
35
  context "with a pattern" do
36
36
  it "returns the matching indices" do
37
- subject.list('oo').should == %w[foo]
37
+ subject.list('oo').map(&:name).should == %w[foo]
38
38
  end
39
39
  end
40
40
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: desi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-07 00:00:00.000000000 Z
12
+ date: 2013-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: boson
@@ -207,7 +207,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
207
207
  version: '0'
208
208
  segments:
209
209
  - 0
210
- hash: -3293702803258038896
210
+ hash: 4007543491113843537
211
211
  required_rubygems_version: !ruby/object:Gem::Requirement
212
212
  none: false
213
213
  requirements:
@@ -216,10 +216,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
216
  version: '0'
217
217
  segments:
218
218
  - 0
219
- hash: -3293702803258038896
219
+ hash: 4007543491113843537
220
220
  requirements: []
221
221
  rubyforge_project:
222
- rubygems_version: 1.8.24
222
+ rubygems_version: 1.8.23
223
223
  signing_key:
224
224
  specification_version: 3
225
225
  summary: A developer tool to quickly set up an Elastic Search local install.