elasticsearch-extensions 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ namespace :test do
22
22
  Rake::TestTask.new(:unit) do |test|
23
23
  Rake::Task['test:ci_reporter'].invoke if ENV['CI']
24
24
  test.libs << 'lib' << 'test'
25
- test.test_files = FileList["test/unit/**/*_test.rb"]
25
+ test.test_files = FileList["test/**/unit/**/*_test.rb"]
26
26
  # test.verbose = true
27
27
  # test.warning = true
28
28
  end
@@ -30,13 +30,13 @@ namespace :test do
30
30
  Rake::TestTask.new(:integration) do |test|
31
31
  Rake::Task['test:ci_reporter'].invoke if ENV['CI']
32
32
  test.libs << 'lib' << 'test'
33
- test.test_files = FileList["test/integration/**/*_test.rb"]
33
+ test.test_files = FileList["test/**/integration/**/*_test.rb"]
34
34
  end
35
35
 
36
36
  Rake::TestTask.new(:all) do |test|
37
37
  Rake::Task['test:ci_reporter'].invoke if ENV['CI']
38
38
  test.libs << 'lib' << 'test'
39
- test.test_files = FileList["test/unit/**/*_test.rb", "test/integration/**/*_test.rb"]
39
+ test.test_files = FileList["test/**/unit/**/*_test.rb", "test/**/unit/**/*_test.rb"]
40
40
  end
41
41
 
42
42
  Rake::TestTask.new(:profile) do |test|
@@ -18,13 +18,14 @@ Gem::Specification.new do |s|
18
18
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_dependency "elasticsearch", '~> 0.4.0'
21
+ s.add_dependency "elasticsearch", '~> 0.4'
22
22
  s.add_dependency "ansi"
23
23
 
24
-
25
24
  s.add_development_dependency "bundler", "> 1"
26
25
  s.add_development_dependency "rake"
27
26
 
27
+ s.add_development_dependency "awesome_print"
28
+
28
29
  s.add_development_dependency "shoulda-context"
29
30
  s.add_development_dependency "mocha"
30
31
  s.add_development_dependency "turn"
@@ -35,7 +36,5 @@ Gem::Specification.new do |s|
35
36
  if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
36
37
  s.add_development_dependency "simplecov"
37
38
  s.add_development_dependency "cane"
38
- s.add_development_dependency "require-prof"
39
- s.add_development_dependency "coveralls"
40
39
  end
41
40
  end
@@ -157,6 +157,33 @@ module Elasticsearch
157
157
  output.join("\n")
158
158
  end
159
159
 
160
+ # Display histogram facets
161
+ #
162
+ def display_histogram_facets(json, options={})
163
+ return unless json['facets']
164
+
165
+ output = [] << ''
166
+
167
+ facets = json['facets'].select { |name, values| values['_type'] == 'histogram' }
168
+ facets.each do |name, values|
169
+ max = values['entries'].map { |t| t['count'] }.max
170
+ padding = 27
171
+ ratio = ((Helpers.width)-padding)/max.to_f
172
+
173
+ histogram = values['entries']
174
+ histogram.each_with_index do |segment, i|
175
+ key = (i == 0) ? "<#{histogram[1]['key']}ms" : "#{segment['key']}ms"
176
+
177
+ output << key.rjust(7) +
178
+ ' ' +
179
+ '█' * (segment['count']*ratio).ceil +
180
+ " [#{segment['count']}]"
181
+ end
182
+ end
183
+
184
+ output.join("\n")
185
+ end
186
+
160
187
  # Display statistical facets
161
188
  #
162
189
  def display_statistical_facets(json, options={})
@@ -13,7 +13,7 @@ module Elasticsearch
13
13
  # representation of the Elasticsearch response for:
14
14
  #
15
15
  # * Search results (hits and highlights)
16
- # * Facets (terms, statistical, date_histogram)
16
+ # * Facets (terms, statistical, histogram, date_histogram)
17
17
  # * Analyze API output
18
18
  # * Shard allocation
19
19
  #
@@ -31,7 +31,11 @@ module Elasticsearch
31
31
  Actions.send(m, self, options)
32
32
  end
33
33
 
34
- output.compact.join("\n")
34
+ unless output.compact.empty?
35
+ output.compact.join("\n")
36
+ else
37
+ self.respond_to?(:awesome_inspect) ? self.awesome_inspect : self.inspect
38
+ end
35
39
  end
36
40
  end
37
41
 
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module Extensions
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+ require 'elasticsearch/extensions/ansi'
3
+
4
+ class Elasticsearch::Extensions::AnsiTest < Test::Unit::TestCase
5
+ context "The ANSI extension" do
6
+ setup do
7
+ @client = Elasticsearch::Client.new
8
+ @client.stubs(:perform_request).returns \
9
+ Elasticsearch::Transport::Transport::Response.new(200, { "ok" => true, "status" => 200, "name" => "Hit-Maker",
10
+ "version" => { "number" => "0.90.7",
11
+ "build_hash" => "abc123",
12
+ "build_timestamp"=>"2013-11-13T12:06:54Z", "build_snapshot"=>false, "lucene_version"=>"4.5.1" },
13
+ "tagline"=>"You Know, for Search" })
14
+ end
15
+
16
+ should "wrap the response" do
17
+ response = @client.info
18
+
19
+ assert_instance_of Elasticsearch::Extensions::ANSI::ResponseBody, response
20
+ assert_instance_of Hash, response.to_hash
21
+ end
22
+
23
+ should "extend the response object with `to_ansi`" do
24
+ response = @client.info
25
+
26
+ assert_respond_to response, :to_ansi
27
+ assert_instance_of String, response.to_ansi
28
+ end
29
+
30
+ should "call the 'awesome_inspect' method when available and no handler found" do
31
+ @client.stubs(:perform_request).returns \
32
+ Elasticsearch::Transport::Transport::Response.new(200, {"index-1"=>{"aliases"=>{}}})
33
+ response = @client.indices.get_aliases
34
+
35
+ response.instance_eval do
36
+ def awesome_inspect; "---PRETTY---"; end
37
+ end
38
+ assert_equal '---PRETTY---', response.to_ansi
39
+ end
40
+
41
+ should "call `to_s` method when no pretty printer or handler found" do
42
+ @client.stubs(:perform_request).returns \
43
+ Elasticsearch::Transport::Transport::Response.new(200, {"index-1"=>{"aliases"=>{}}})
44
+ response = @client.indices.get_aliases
45
+
46
+ assert_equal '{"index-1"=>{"aliases"=>{}}}', response.to_ansi
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+ RUBY_1_8 = defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
2
+
3
+ exit(0) if RUBY_1_8
4
+
5
+ require 'simplecov' and SimpleCov.start { add_filter "/test|test_/" } if ENV["COVERAGE"]
6
+
7
+ require 'test/unit'
8
+ require 'shoulda-context'
9
+ require 'mocha/setup'
10
+ require 'ansi/code'
11
+ require 'turn' unless ENV["TM_FILEPATH"] || ENV["NOTURN"] || RUBY_1_8
12
+
13
+ require 'elasticsearch/extensions'
14
+
15
+ module Elasticsearch
16
+ module Test
17
+ class IntegrationTestCase < ::Test::Unit::TestCase
18
+ end
19
+ end
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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: 2013-10-23 00:00:00.000000000 Z
12
+ date: 2013-12-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: elasticsearch
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.4.0
21
+ version: '0.4'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.4.0
29
+ version: '0.4'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: ansi
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -76,7 +76,7 @@ dependencies:
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  - !ruby/object:Gem::Dependency
79
- name: shoulda-context
79
+ name: awesome_print
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -92,23 +92,7 @@ dependencies:
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  - !ruby/object:Gem::Dependency
95
- name: mocha
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- - !ruby/object:Gem::Dependency
111
- name: turn
95
+ name: shoulda-context
112
96
  requirement: !ruby/object:Gem::Requirement
113
97
  none: false
114
98
  requirements:
@@ -124,7 +108,7 @@ dependencies:
124
108
  - !ruby/object:Gem::Version
125
109
  version: '0'
126
110
  - !ruby/object:Gem::Dependency
127
- name: yard
111
+ name: mocha
128
112
  requirement: !ruby/object:Gem::Requirement
129
113
  none: false
130
114
  requirements:
@@ -140,7 +124,7 @@ dependencies:
140
124
  - !ruby/object:Gem::Version
141
125
  version: '0'
142
126
  - !ruby/object:Gem::Dependency
143
- name: ruby-prof
127
+ name: turn
144
128
  requirement: !ruby/object:Gem::Requirement
145
129
  none: false
146
130
  requirements:
@@ -156,7 +140,7 @@ dependencies:
156
140
  - !ruby/object:Gem::Version
157
141
  version: '0'
158
142
  - !ruby/object:Gem::Dependency
159
- name: ci_reporter
143
+ name: yard
160
144
  requirement: !ruby/object:Gem::Requirement
161
145
  none: false
162
146
  requirements:
@@ -172,7 +156,7 @@ dependencies:
172
156
  - !ruby/object:Gem::Version
173
157
  version: '0'
174
158
  - !ruby/object:Gem::Dependency
175
- name: simplecov
159
+ name: ruby-prof
176
160
  requirement: !ruby/object:Gem::Requirement
177
161
  none: false
178
162
  requirements:
@@ -188,7 +172,7 @@ dependencies:
188
172
  - !ruby/object:Gem::Version
189
173
  version: '0'
190
174
  - !ruby/object:Gem::Dependency
191
- name: cane
175
+ name: ci_reporter
192
176
  requirement: !ruby/object:Gem::Requirement
193
177
  none: false
194
178
  requirements:
@@ -204,7 +188,7 @@ dependencies:
204
188
  - !ruby/object:Gem::Version
205
189
  version: '0'
206
190
  - !ruby/object:Gem::Dependency
207
- name: require-prof
191
+ name: simplecov
208
192
  requirement: !ruby/object:Gem::Requirement
209
193
  none: false
210
194
  requirements:
@@ -220,7 +204,7 @@ dependencies:
220
204
  - !ruby/object:Gem::Version
221
205
  version: '0'
222
206
  - !ruby/object:Gem::Dependency
223
- name: coveralls
207
+ name: cane
224
208
  requirement: !ruby/object:Gem::Requirement
225
209
  none: false
226
210
  requirements:
@@ -255,6 +239,8 @@ files:
255
239
  - lib/elasticsearch/extensions/ansi/helpers.rb
256
240
  - lib/elasticsearch/extensions/ansi/response.rb
257
241
  - lib/elasticsearch/extensions/version.rb
242
+ - test/ansi/unit/ansi_test.rb
243
+ - test/test_helper.rb
258
244
  homepage: ''
259
245
  licenses:
260
246
  - Apache 2
@@ -280,5 +266,7 @@ rubygems_version: 1.8.23
280
266
  signing_key:
281
267
  specification_version: 3
282
268
  summary: Extensions for the Elasticsearch Rubygem
283
- test_files: []
269
+ test_files:
270
+ - test/ansi/unit/ansi_test.rb
271
+ - test/test_helper.rb
284
272
  has_rdoc: